akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cassert>
#include <cstdint>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<long long>;
using VVL = vector<VL>;

const long long INF = 1e18;
const int N_CONTEST = 26;

// すべて 0-indexで考える。結果の出力時に1を足す

struct Input {
	int D;
	VI c;
	VVI s;
};

Input get_input() {
	int D;
	cin >> D;
	VI c(N_CONTEST);
	VVI s(D, VI(N_CONTEST));

	for (int i = 0; i < c.size(); i++) {
		cin >> c[i];
	}
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < s[i].size(); j++) {
			cin >> s[i][j];
		}
	}

	Input input;
	input.D = D;
	input.c = c;
	input.s = s;

	return input;
}

void show_results(const VI &t) {
	for (auto x: t) {
		cout << x + 1 << endl;
	}
}

long long calc_score(const Input& input, const VI& t) {
	long long score = 0;
	VI lastdays(N_CONTEST, -1);
	for (int i = 0; i < t.size(); i++) {
		score += input.s[i][t[i]];

		lastdays[t[i]] = i;
		for (int j = 0; j < N_CONTEST; j++) {
			score -= (long long) input.c[j] * (i - lastdays[j]);
		}
	}

	return score;
}

void solve_b() {
	auto input = get_input();
	int tmp;
	VI t;
	VL scores(input.D);
	for (int i = 0; i < input.D; i++) {
		cin >> tmp;
		// 0-index
		t.emplace_back(tmp - 1);
		scores[i] = calc_score(input, t);
	}

	for (auto x: scores) {
		cout << x << endl;
	}
}


int main() {
	solve_b();
	return 0;
}

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

int main()
{
    int n,i,k,p,d,c;

    cin>>n;
    d=n;
    c=0;
    while(n>0)
    {
        c=c+(n%10);
        n=n/10;

    }
    if(d%c==0)cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


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


using namespace std;

long long dp[123456];

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
		dp[i] = 1e12;
	}
	dp[0] = 0;
	
	for(int i = 1; i < n; i++) {
		for(int j = 1; j <= k; j++) {
			if ( (i-j) >= 0 )
				dp[i] = min(dp[i], dp[i-j]+abs(h[i] - h[i-j]));
		}
	}

	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,s1,s2,s3,m1,m2;
    cin>>a>>b;
    s1=a+b;
    s2=a-b;
    s3=a*b;
    m1=max(s1,s2);
    m2=max(m1,s3);
    cout<<m2<<endl;



    return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// マラソン用時間計測
clock_t start_clock;
constexpr double time_limit = 1.919114514; // 実行時間[s]より0.1ms程度余裕をあける
constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
inline bool intime() { return nowtime() < time_limit; }

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (int i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (int i=(is), i##_end=(ie); i<=i##_end; i++)
#define FOREACH(i, arr) for (auto &i : arr)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using ll = long long;
using namespace std;

// 汎用クラス
struct union_find {
    vector<int> par;
    vector<int> num;
    union_find(int n) : par(n, 0), num(n, 1) { iota(ALL_OF(par), 0); }
    int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
    bool same(int i, int j) { return root(i) == root(j); }
    void unite(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        if (ri != rj) {
            if (num[ri] > num[rj]) swap(ri, rj);
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
};

// main前実行のためのダミークラス
struct preexec_dummy {
    preexec_dummy() {
        start_clock = clock();
    }
} preexec_dummy_instance;

int main() {
    
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> ab(n, make_pair(0ll, 0ll));
    REP(i, n) {
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ALL_OF(ab));

    int need = m;
    ll ans = 0;
    REP(i, ab.size()) {
        if (need >= ab[i].second) {
            need -= ab[i].second;
            ans += ab[i].second * ab[i].first;
        } else {
            ans += need * ab[i].first;
            need = 0;
        }
        if (need <= 0) break;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1792
import itertools

n = int(input())
nums = list(map(int, input().split()))
count = 0
for i, j, k in itertools.combinations(nums, 3):
    if i != j and i != k and j != k:
        L = [i, j, k]
        L = sorted(L)
        if L[2] < L[0] + L[1]:
            count += 1


print(count)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    vector<int> data(n);
    rep(i,0,n){
        cin >> data[i];
    }
    int s = data.at(0);
    rep(i,1,n){
        s^=data[i];
    }
    rep(i,0,n){
        int ans = s^data[i];
        cout<<ans<<" ";
    }
    cout<<endl;
    
  return 0;
}

Measured memory_bytes: 4048
#include<cstdio> 
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring> 
using namespace std;
const int MaxN = 200;

int a[MaxN + 5][MaxN + 5];

void floyd()
{
	for(int k = 0;k <= 9; k++)
		for(int i = 0;i <= 9; i++)
			for(int j = 0;j <= 9; j++)
				//a[i][j] = a[i][j] || (a[i][k] && a[k][j]);
				a[i][j] = min(a[i][j],a[i][k] + a[k][j]);
}

int main()
{
	int h,w,z;
	int ans = 0;
	scanf("%d %d",&h,&w);
	for(int i = 0;i <= 9;i++)
	{
		for(int j = 0;j <= 9;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	floyd();
	for(int i = 1;i <= h;i++)
	{
		for(int j = 1;j <= w;j++)
		{
			scanf("%d",&z);
			if(z==-1) continue;
			ans += a[z][1];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Created on Tue Mar  3 22:38:51 2020

@author: Kanaru Sato
"""

A = []
[A.append(list(map(int, input().split()))) for i in range(0,3)]

N = int(input())

b = []
[b.append(int(input())) for i in range(0,N)]

flag = [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]

for i in range(0,3):
    for j in range(0,3):
        if A[i][j] in b:
            flag[i][j] = 1

column = 0
raw = 0
naname = 0

for i in range(0,3):
    column += flag[i][0]*flag[i][1]*flag[i][2]
    raw += flag[0][i]*flag[1][i]*flag[2][i]
naname = flag[0][0]*flag[1][1]*flag[2][2]+flag[0][2]*flag[1][1]*flag[2][0]


if column>=1 or raw>=1 or naname>=1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
 
#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tolower(c) char(c+0x20)
#define toupper(c) char(c-0x20)

const ll MAX_N = 100000;
 
int main(void){
    ll a,b,c,d;
    string s,t,u;
 
    //cin >> a >> b>> c >> d;
    cin >> s >> t;// >> u;
    if (s=="H" && t=="H") cout << "H";
    if (s=="H" && t=="D")cout << "D";
    if (s=="D" && t=="H")cout << "D";
    if (s=="D" && t=="D")cout << "H";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  char s;
  cin >> s;
  bool Is = false;
  string str1="aiueo";
  for (int a=0; a<5; a++){
    if (str1.at(a) == s){
      cout << "vowel" << endl;
      Is = true;
      break;
    }
  }
  if (Is == false){
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"

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

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int N; cin >> N;
	vector<int> H(N);
	rep(i, N)cin >> H[i];

	rep(i, N - 1) {
		int dif = H[i + 1] - H[i];
		if (dif < -1) {
			cout << "No";
			return 0;
		}
		if (dif == -1) {
			if (i != 0 && H[i - 1] == H[i]) {
				cout << "No";
				return 0;
			}
			H[i] -= 1;
		}
		if ((dif >= 0) && (H[i - 1] != H[i]))H[i] -= 1;
	}
	cout << "Yes";
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int x , y;
		int za = (int)Math.pow(10 , 9);
		int zb = -(int)Math.pow(10 , 9);
		int wa = (int)Math.pow(10 , 9);
		int wb = -(int)Math.pow(10 , 9);
		for(int i = 0 ; i < n ; i++){
			x = Integer.parseInt(sc.next());
			y = Integer.parseInt(sc.next());
			za = Math.min(x + y , za);
			zb = Math.max(x + y , zb);
			wa = Math.min(x - y , wa);
			wb = Math.max(x - y , wb);
		}
		sc.close();
		ou.println(Math.max(zb - za , wb - wa));
		ou.flush();
	}
}

Measured memory_bytes: 59240
// 2018/06/25 Tazoe

#include <iostream>
using namespace std;

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

	int N;
	cin >> N;

	int flg = 0;		// 重複フラグ

	for(int i=0; i<N; i++){
		int s, f;
		cin >> s >> f;

		if(f<=a || b<=s){
			continue;
		}
		else{
			flg = 1;
		}
	}

	cout << flg << endl;

	return 0;
}



Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;
//切り離すという問題は、
//最後の一個からくっつけていく問題と考える

//こういう時のアルゴリズム
//Union-Find(またはDisjoint Set)

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] In = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = In[0];
            int m = In[1];
            var uf = new unionFind(n);
            var stack = new Stack<Pair>();
            for(int i=0; i < m; i++)
            {
                int[] In2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                int a = In2[0];
                int b = In2[1];
                a--;b--;
                stack.Push(new Pair(a, b));
            }
            long sum = (long)n * (n - 1) / 2;
            var ans = new Stack<long>();
            ans.Push(sum);
            while (stack.Count > 1)//最後の一個は邪魔
            {
                var p = stack.Pop();
                int a = p.x;
                int b = p.y;
                //つながってなかったのがつながったとき
                if (uf.root(a)!=uf.root(b))
                {
                    sum -= (long)uf.Size(a) * uf.Size(b);
                    ans.Push(sum);
                    uf.Connect(a, b);
                }
                else ans.Push(sum);
            }
            while (ans.Count !=0 )
            {
                Console.WriteLine(ans.Pop());
            }
        }
    }
    public class unionFind
    {
        //親の番号を格納、親だった場合は-1 <-ふつうのunionfind
        //今回は、親だった場合　-(その集合のサイズ)にする
        int[] Parent;
        //まずすべて-1で初期化、
        public unionFind(int n)
        {
            Parent = new int[n];
            Parent = Enumerable.Repeat(-1, n).ToArray();
        }
        //aがどのグループに属しているか
        public int root(int a)
        {
            if (Parent[a] < 0) return　a;
            return Parent[a] = root(Parent[a]);
        }
        //自分のいるグループの頂点数を調べる
        public int Size(int a)
        {
            return -Parent[root(a)];//親をとってきたい
        }
        //aとｂをくっつける
        public bool Connect(int a, int b)
        {
            //aとbをくっつけるのではなく、root(A)とroot(B)をくっつける
            a = root(a);
            b = root(b);
            //すでにくっついているとき
            if (a == b) return false;
            //大きい方(a)が小さいほう(b)をくっつけたい
            //大小が逆ならひっくり返す
            if (Size(a) < Size(b))
            {
                int tmp = a;
                a = b;
                b = tmp;
            }
            //aのサイズを更新する
            Parent[a] += Parent[b];
            //bの親をaに変更する
            Parent[b] = a;
            return true;
        }
    }
    public struct Pair
    {
        public int x, y;
        public Pair(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 50312
s = list(input())
sur_list = [0 for i in range(2019)]
sur = 0
keta = 1
ans = 0

s.reverse()

for i in range(len(s)):
    keta = (keta*10)%2019
    sur_list[sur] += 1
    sur = (int(s[i]) * keta + sur) % 2019
    ans += sur_list[sur]

print(ans)


Measured memory_bytes: 10520
mo = 10 ** 9 + 7
n, k = map(int, input().split())
def rev(u):
    return pow(u, mo - 2, mo)
def C(p, q):
    ans = 1
    for i in range(q):
        ans = ans * (p - i) % mo
    for i in range(q):
        ans = ans * rev(i + 1) % mo
    return (ans + mo) % mo
if k >= n - 1:
    print(C(2 * n - 1, n))
    exit()
u, v = 1, 1
ans = 1
for i in range(k):
    u = u * (n - 1 - i) * rev(i + 1) % mo
    v = v * (n - i) * rev(i + 1) % mo
    ans = (ans + u * v) % mo
print(ans)

Measured memory_bytes: 40812
using System;
class Program
{
	static void Main(string[] args)
	{
        string input = Console.ReadLine();

        if(input[input.Length-1] == 's')
        {
            //出力
		    Console.WriteLine(input + "es");
        }
        else
        {
            //出力
		    Console.WriteLine(input + "s");
        }
		
	}
}

Measured memory_bytes: 17324
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

using namespace std;

#define ll long long

int main(){
	ll n;
	cin >> n;
	vector<ll> yakusu;
	for(int i = 1;i < sqrt(n);i++){
		if(n%i==0){
			yakusu.push_back(i);
			yakusu.push_back(n/i);
		}
	}
	ll ans = 0;
	for(int i = 0;i < yakusu.size();i++){
		// cout << yakusu[i] << endl;
		ll value = n/yakusu[i] - 1;
		if(value == 0)continue;
		ll sho = n/value;
		ll amari = n%value;
		if(sho==amari){
			ans += value;
			// cout << value << endl;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      ans += (d.at(i) * d.at(j));
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque
import heapq
from itertools import combinations
import bisect


import math

a,b,h,m=map(int,input().split())
aa=(h+m/60.0)*30.0
bb=m*6
t=aa-bb
# print(t)
ans=(a*a+b*b-2*a*b*math.cos(t*math.pi/180.0))**0.5
print(ans)



Measured memory_bytes: 9792
#include <iostream>

using namespace std;

int main() {
	string s;
	string ans = "";
	cin >> s;
	for(int i = 0; i < s.length(); ++i){
		if(s[i] == '0'){
			ans += "0";
		}
		if(s[i] == '1'){
			ans += "1";
		}
		if(s[i] == 'B'){
			if(ans.length() == 0) {}
			else {
				ans = ans.substr(0, ans.length() - 1);
			}
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n,0);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    for(int i = k;i < n;i++){
        if(a[i] > a[i-k]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }

    }
    
}


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

#define BUF_SIZE 20
#define STR_MAX 100002
int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num, queries;
  sscanf(line, "%d %d", &num, &queries);

  char str[STR_MAX];
  int cum[STR_MAX] = {0};
  if(!fgets(str, STR_MAX, fp)) return 0;

  int flag = 0;
  int i, j;
  char *tmp;
  for(tmp = str, i = 1; *tmp != '\n'; tmp++, i++) {
    switch(*tmp) {
      case 'A':
        flag = 1;
        break;
      case 'C':
        if(flag) cum[i] = 1;
        // fall through
      default:
        flag = 0;
        break;
    }
  }
  for(i = 1; i <= num; i++) {
    cum[i] = cum[i-1] + cum[i];
  }


  for(i = 0; i < queries; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    int start, end;
    sscanf(line, "%d %d", &start, &end);
    printf("%d\n", cum[end] - cum[start]);
  }

  return 0;
}

Measured memory_bytes: 1280
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        double[] kingaku = new double[n];
        String[] JpyOrBtc = new String[n];
        double sum = 0;
        for (int i = 0; i < n; i++) {
            kingaku[i]  = sc.nextDouble();
            JpyOrBtc[i] = sc.next();
        }
        for (int i = 0; i < n; i++) {
            if (JpyOrBtc[i].equals("JPY")) {
                sum += kingaku[i];
            }else{
                sum += (kingaku[i]*380000);
            }
        }

        System.out.println(sum);

        sc.close();
    }
    
    private static long gcd(Long m, long n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }

    private static long[][] Combination_nCk(long n, long k) {
        n++; k++;
        long[][] ans = new long[(int)n][(int)k];
        for (int i = 0; i < n; i++) {
            ans[i][0] = 1;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = ans[i][j] + ans[i][j+1];
                }
            }
        }
        return ans;
    }
}

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

namespace Aizu
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = int.Parse(Console.ReadLine());
            var answers = new List<int>();

            for(var i = 0; i < q; i++)
            {
                var x = Console.ReadLine();
                var y = Console.ReadLine();

                var lcsLength = new int[x.Length + 1, y.Length + 1];

                for(var j = 1; j <= x.Length; j++)
                {
                    for(var k = 1; k <= y.Length; k++)
                    {
                        if(x[j - 1] == y[k - 1])
                        {
                            lcsLength[j, k] = lcsLength[j - 1, k - 1] + 1;
                        }

                        lcsLength[j, k] = Math.Max(lcsLength[j, k], Math.Max(lcsLength[j - 1, k], lcsLength[j, k - 1]));
                    }
                }

                answers.Add(lcsLength[x.Length, y.Length]);
            }

            answers.ForEach(value => Console.WriteLine(value));
        }
    }
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

string query(int a,int b){
  cout<<"? "<<a<<" "<<b<<endl;
  fflush(stdout);
  string res;
  cin>>res;
  return res;
}

void answer(string s){
  cout<<"! "<<s<<endl;
}

int A,B;
vector<int> ps;

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

  cin>>A>>B;
  int N=A+B;

  if(A<=B){
    cout<<"Impossible"<<endl;
    return 0;
  }

  int crt=0;
  while(ps.size()<B+1){
    if(ps.size()==0){
      ps.push_back(crt++);
    }
    if(ps.size()==B+1)break;

    string q=query(ps.back(),crt);
    if(q=="Y"){
      ps.push_back(crt);
    }else{
      ps.pop_back(); B--;
    }
    crt++;
  }

  int k=ps.back();
  string s;
  rep(i,N){
    if(query(k,i)=="Y")s+="1";
    else s+="0";
  }
  answer(s);

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int sumn = i * (i + 1) / 2;
    if (sumn >= N) {
      int diff = sumn - N;
      for (int j = 1; j <= i; j++) {
        if (diff == 0 || j != diff) cout << j << '\n';
      }
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int n,m,j,k;
    int a,b,c;
    int  cnt=0;
    map<int ,int>mp;
    cin>>n>>k;
    while(k--)
    {
        cin>>a;
        while(a--)
        {
            cin>>b;
            mp[b]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(mp[i])
            continue;
        cnt++;
    }
    cout<<cnt<<endl;
}


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for (int i = 0; i < M; i++) cin >> A[i];
  int costToZero = 0;
  int costToN = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (i < X && i == A[j]) costToZero++;
      else if (i == A[j]) costToN++;
    }
  }
  int ans = costToZero < costToN ? costToZero : costToN;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      char[] array = s.toCharArray();
      int first = 0;
      int end = s.length();
      for(int i = 0;i < end;i++){
      	if(s.substring(i,i+1).equals("A")){
          first = i+1;
          break;
        }
      }
      for(int i = end;i > 0;i--){
      	if(s.substring(i-1,i).equals("Z")){
        	end = i;
          break;
        }
      }
      System.out.println(end-first+1);
    }
}


Measured memory_bytes: 34796
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( (n>>k)&1 )

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end\n"<<endl;
}

template<class T>
void VPout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i].first<<" "<<V[i].second<<'\n';
    }
    cout<<"end\n"<<endl;
}


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));




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

    int N;
    cin>>N;
    vector<ll> A(N),B(N);
    for(int i=0;i<N;i++) cin>>A[i];
    for(int i=0;i<N;i++) cin>>B[i];

    priority_queue<pli> que;
    for(int i=0;i<N;i++){
        que.push(pli(B[i],i));
    }
    ll ans=0;
    while(!que.empty()){
        int now=que.top().second;
        que.pop();
        ll x=B[(now+1)%N]+B[(now-1+N)%N];
        if(A[now]==B[now]){
            continue;
        }
        if(A[now]>B[now] || B[now]/x==0){
            cout<<-1<<endl;
            return 0;
        }

        if(x<=A[now]){
            if( (B[now]-A[now])%x!=0 ){
                cout<<-1<<endl;
                return 0;
            }
            ans+=(B[now]-A[now])/x;
        }else{
            ans+=B[now]/x;
            B[now]%=x;
            if(B[now]!=A[now]){
                que.push(pli(B[now],now));
            }
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int n,m,i,j;
long long dp[300][10];
bool edge[10][10];

int main(){
	scanf("%d%d", &n, &m);
	
	for(i = 0; i < m; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		edge[x][y] = 1;
		edge[y][x] = 1;
	}
	
	dp[1][0] = 1LL;
	
	for(i = 0; i < (1 << n); i++){
		for(j = 0; j < n; j++){
			if((i & (1 << j)) == 0) continue;
			for(int ii = 0; ii < n; ii++){
				if(i & (1 << ii) || !edge[j][ii]) continue;
				int newmask = i | (1 << ii);
				dp[newmask][ii] += dp[i][j];
			}
		}
	}
	
	long long res = 0;
	
	for(i = 0; i < n; i++)
	res += dp[(1 << n) - 1][i];
	
	printf("%lld\n", res);
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A <= C && C <= B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

typedef long long ll;
const int N = 110, inF = N * N;

int n, s, ans = inF, a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	int now = 0;
	for (int i = 0; i < n; i++) {
		now += a[i];
		if(i && i != n - 1)
			ans = min(ans, abs(s - 2 * now));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
#define MAX_V (110)

signed main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	bool flag = false;
	int cnt = 0;
	while(1){
		rep(i, n){
			if(a[i] % 2)
				flag = true;
			else
				a[i] /= 2;
		}
		if(flag)break;
		flag = false;
		cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::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...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
	ll m  =1e9 + 7;
ll fastexpo(ll x,ll y)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
ll a[L];
void fff()
{
	int n;
	cin >> n;
	ll prod = 0,cur;
	FOR(i,0,n)
	{
		cin >> a[i];
		prod = (prod + a[i])%m;
	}
	ll ans = 0;
	FOR(i,0,n)
	{
		cur = (prod - a[i] + m)%m;
		// debug(prod, i, a[i], cur);
		ans = (ans + (a[i]*cur)%m)%m;
	}
	cout << (ans*fastexpo(2,m-2))%m << ln;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 5216
// Problem : B - Product Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int a,b,c,d;
	cin >>a >> b >> c >> d;
	int ans=-1e18;
	ans = max(ans,a*c);
	ans = max(ans,a*d);
	ans = max(ans,b*c);
	ans = max(ans,b*d);
	cout << ans;	
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3648
n = int(input())
a = list(map(int,input().split()))
amax = max(a)
ans = 0
numlist = [0] * amax

for i in range(n):
    if numlist[a[i]-1] != 0:
        numlist[a[i]-1] = 2
        continue
    else:
        for j in range(1, amax // a[i] + 1):
            numlist[a[i] * j - 1] += 1
for i in range(n):
    if numlist[a[i]-1] == 1:
        ans += 1
        
print(ans)


Measured memory_bytes: 32292
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// グラフ上の深さ優先探索
vector<bool> seen;
void dfs(const Graph G, int v, int a, int b) {
  seen[v] = true; // vを訪問済にする
  // vから行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]||(v==a&&next_v==b)||(v==b&&next_v==a)) continue; // next_vが探索済だったらスルー
    dfs(G, next_v, a, b); // 再帰的に探索
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i=0; i<M; i++) cin >> a[i] >> b[i], a[i]--, b[i]--;
  // グラフへの入力(重みなし)
  Graph G(N);
  for (int i=0; i<M; i++) {
    G[a[i]].push_back(b[i]);
    // 無向グラフの場合は以下を追加
    G[b[i]].push_back(a[i]);
  }
  // i番目の辺を除いた時を考える
  int res = 0;
  for (int i=0; i<M; i++) {
    for (int j=0; j<N; j++) {
      seen.assign(N, false);
      dfs(G, j, a[i], b[i]);
      for (int k=0; k<N; k++) {
        if (!seen[k]) {
          res++;
          break;
        }
      }
    }
  }
  cout << res/N << endl;
  return 0;
}

Measured memory_bytes: 3748
import sys
input = sys.stdin.readline

from collections import deque

def main():
    n,m = map(int, input().split())
    qp = [tuple(map(int, input().split())) for _ in range(m)]

    qp.sort(key=lambda x:x[1])

    qp = deque(qp)

    ans = 0
    pre = 0

    while qp:
        a,b = qp.popleft()
        if pre<a:
            ans += 1
            pre = b-1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 18520
using System;
using System.Linq;

namespace ITP1_9_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int q = int.Parse(Console.ReadLine());

            for (int i = 0; i < q; i++)
            {
                string input = Console.ReadLine();
                int a = int.Parse(input.Split(' ')[1]);
                int b = int.Parse(input.Split(' ')[2]);
                switch(input.Split(' ')[0])
                {
                    case "reverse":
                        string cut = new string(str.Substring(a, b - a + 1).Reverse().ToArray());
                        str = str.Substring(0, a) + cut + str.Substring(b + 1);
                        break;

                    case "replace":
                        string cut2 = input.Split(' ')[3];
                        str = str.Substring(0, a) + cut2 + str.Substring(b + 1);
                        break;

                    case "print":
                        Console.WriteLine(str.Substring(a, b - a + 1));
                        break;
                }
            }
        }
    }
}


Measured memory_bytes: 9164
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	var sum int
	if a >= b {
		sum += b
	} else {
		sum += a
	}

	if c >= d {
		sum += d
	} else {
		sum += c
	}
	fmt.Print(sum)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i)cin>>vec[i];
	for(int i = 1; i < n; ++i){
		if(vec[i] > vec[i - 1])vec[i]--; 
	}
	bool ok = true;
	for(int i = 1; i < n; ++i)if(vec[i] < vec[i - 1])ok=false;
	if(ok){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;

	
	return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)
#define MIN(x, y) (x > y ? y : x)

u64 w[101], v[101];
u64 dp[101][100100];

int main() {
  u64 n, wmax;
  cin >> n >> wmax;

  rep(i, n) {
    u64 wi, vi;
    cin >> wi >> vi;
    w[i] = wi;
    v[i] = vi;
  }

  for (auto &d : dp) {
    for (auto &di : d) {
      di = wmax * 10;
    }
  }

  dp[0][0] = 0;

  rep(i, n) {
    rep(val, 1000 * n + 1) {
      dp[i + 1][val] = dp[i][val];
      if (val >= v[i]) {
        dp[i + 1][val] = MIN(dp[i + 1][val], dp[i][val - v[i]] + w[i]);
      }
    }
  }

  u64 ans = 0;
  rep(val, 1000 * n + 1) {
    if (dp[n][val] <= wmax) {
      ans = val;
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 82580
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

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

    ll n, s;
    cin >> n >> s;
    vector<ll> a(n);//aは0-origin
    for (ll i=0; i<n; i++) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(n+1, vector<ll>(s+1, 0)); // dp[i][j] : Aiまで考えたときTとUの積集合の要素を添え字としたaの和がjであるような場合の数 dpのiは1-origin
    dp[0][0] = 1;

    for (int i=0; i<n; i++) {
        for (int j=0; j<s+1; j++) {
            dp[i+1][j] += dp[i][j] * 2;
            if(j-a[i]>=0)dp[i+1][j] += dp[i][j-a[i]]; 
            dp[i+1][j] %= mod;
        }
    }
    cout << dp[n][s] << endl;


}


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

using namespace std;

typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const double pi=acos(-1);
const int maxn=2e5+5;
const int mod=1e9+7;

int main()
{
    ll t1,t2;
    ll a1,a2,b1,b2;
    sll2(t1,t2);
    sll2(a1,a2);
    sll2(b1,b2);
    if(a1<b1&&a1*t1+a2*t2<b1*t1+b2*t2||a1>b1&&a1*t1+a2*t2>b1*t1+b2*t2)
          cout<<0<<endl;
    else if(a1*t1+a2*t2==b1*t1+b2*t2)
        cout<<"infinity"<<endl;
    else
    {
        if(a1<b1)
        {
            ll t=a1;
            a1=b1;
            b1=t;
            t=a2;
            a2=b2;
            b2=t;
        }
        ll s1=(a1-b1)*t1;
        ll s2=b1*t1+b2*t2-a1*t1-a2*t2;
        ll cj=s2;
        ll sum=0;
        if(s1%cj==0)
            sum+=2*(s1/cj);
        else
            sum+=2*(s1/cj)+1;
        printf("%lld\n",sum);
    }
    return 0;
}
/*120 157
339 381
555 213*/


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = 1
c = 0
d = {}
t = []
# 順番をdictで持つ
while not s in d.keys():
    d[s] = c
    t.append(s)
    c += 1
    s = a[s-1]
l = c - d[s]
m = len(d.keys()) - l
if m >= k:
    print(t[k])
else:
    print(t[(k - m) % l + m])



Measured memory_bytes: 38748
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
using ll = long long;

const int INF = 1001001001;

int main()
{
	ll n(0), a(0), b(0), ab(0), now(0), ans(0), i(0);
	
	cin>>n>>a>>b;
	
	ab = a+b;
	
	if(n == 0)cout<<"0";
	else if(a >= n)cout<<n;
	else if(ab >= n)cout<<a;
	else{
	    ll x = n % ab;
	    
	    
	    
	    ll y = min(a, x);
	    
	    
	    
	    ll z = (n / ab) * a;
	    
	    ans = y + z;
	    
	    cout<<ans;
	}
}

Measured memory_bytes: 256
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

ll n,ans=0;
vs mk;
void make753(ll a){
    if(a > n) return;
    mk.push_back(to_string(a));
    make753(10*a+3);
    make753(10*a+5);
    make753(10*a+7);
}

bool chk753(string s){
    bool c3=false,c5=false,c7=false;
    rep(i,s.size()){
        if(s[i] == '3') c3 = true;
        if(s[i] == '5') c5 = true;
        if(s[i] == '7') c7 = true;
    }
    if(c3&&c5&&c7) return true;
    else return false;
}

int main(){
    cin >> n;
    make753(3);
    make753(5);
    make753(7);
    rep(i,mk.size()){
        ans += chk753(mk[i]) == 1;
    }
    cout << ans << endl;
    return 0;
}  


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S;
  cin >> S;
  vector<bool> flag(4);
  for(char c: S) {
    if(c == 'N') flag[0] = 1;
    else if(c == 'S') flag[1] = 1;
    else if(c == 'W') flag[2] = 1;
    else flag[3] = 1;
  }
  cout << ((!(flag[0]^flag[1]) && !(flag[2]^flag[3])) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

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

    int k;
    cin >> k;

    ll sum = 0;
    REP(a, k) REP(b, k) REP(c, k) {
        sum += gcd(a+1, gcd(b+1, c+1));
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;
typedef pair<int,int> pii;
const int N = 100010;
int _w;

int n, m, deg[N];

namespace G {
	int head[N], nxt[N*2], to[N*2], w[N*2], eid;
	void init() {
		eid = 0;
		memset(head, -1, sizeof head);
	}
	void link( int u, int v ) {
		to[eid] = v, nxt[eid] = head[u], head[u] = eid++;
		to[eid] = u, nxt[eid] = head[v], head[v] = eid++;
	}
}

vector<int> con;
bool vis[N];

void bfs( int s ) {
	int cnt = 0, maxd = 0;
	queue<int> q;
	q.push(s), vis[s] = 1;
	while( !q.empty() ) {
		int u = q.front(); q.pop();
		++cnt, maxd = max(maxd, deg[u]);
		using namespace G;
		for( int i = head[u]; ~i; i = nxt[i] ) {
			int v = to[i];
			if( !vis[v] ) {
				vis[v] = 1;
				q.push(v);
			}
		}
	}
	if( cnt > 1 ) {
		con.push_back(maxd/2);
	}
}

vector<int> eq;
int cur[N];

void euler( int u ) {
	using namespace G;
	for( int &i = cur[u]; ~i; ) {
		int nowi = i;
		i = nxt[i];
		int v = to[nowi];
		if( w[nowi] ) continue;
		w[nowi] = w[nowi^1] = 1;
		euler(v);
	}
	eq.push_back(u);
}

stack<int> stk;

int main() {
	cin >> n >> m;
	G::init();
	for( int i = 0; i < m; ++i ) {
		int u, v;
		_w = scanf( "%d%d", &u, &v );
		G::link(u, v);
		++deg[u], ++deg[v];
	}
	for( int i = 1; i <= n; ++i )
		if( deg[i] & 1 ) {
			puts("No");
			return 0;
		}
	for( int i = 1; i <= n; ++i )
		if( !vis[i] )
			bfs(i);
	if( con.size() > 3 ) {
		puts("No");
		return 0;
	}
	int sum = 0;
	for( int tmp : con )
		sum += tmp;
	if( sum >= 3 ) puts("Yes");
	else {
		int cnt4 = 0;
		for( int i = 1; i <= n; ++i )
			if( deg[i] == 4 )
				++cnt4;
		if( cnt4 >= 3 ) {
			puts("Yes");
			return 0;
		}
		for( int i = 1; i <= n; ++i )
			cur[i] = G::head[i];
		euler(1);
		int ans = 0;
		memset(vis, 0, sizeof vis);
		for( auto it = eq.rbegin(); it != eq.rend(); ++it ) {
			int u = *it;
			if( vis[u] == 0 ) {
				vis[u] = 1;
				stk.push(u);
			} else {
				++ans;
				while(1) {
					int v = stk.top();
					stk.pop();
					vis[v] = 0;
					if( v == u ) break;
				}
				stk.push(u);
				vis[u] = 1;
			}
		}
		puts( ans >= 3 ? "Yes" : "No" );
	}
	return 0;
}


Measured memory_bytes: 13740
#include<bits/stdc++.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define iof ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897
const ll mod =1000000007;
#define inf 1<<60
using namespace std;

int main()
{
   ll n; cin>>n;
   n--;
   cout<<n*(n+1)/2;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
#define pb push_back
#define inf 1e9
#define maxn 100003
using namespace std;
vector<int> a[maxn];
int par[maxn];
int size[maxn];
void dfs(int u, int parent){
	int v;
	par[u] = parent;
	int s = 1;
	for(int i=0;v = a[u][i];i++){
		if(v!=parent)	{
			dfs(v,u);			
			s+= size[v];
		}
	}
	size[u] = s;	
}
int n,u,v;
main(){
	cin >> n;
	For(i,1,n-1){
		scanf("%d%d",&u,&v);
		a[u].pb(v);
		a[v].pb(u);
	}
	For(i,1,n) a[i].pb(0);
  	dfs(1,1);
  	int temp = n;
  	int cnt = 0;
  	while(par[temp]!=1){
  		temp = par[temp];
  		cnt++;
	}
	temp = n;	
	For(i,1,cnt/2){
		temp = par[temp];
	}
	if(n - size[temp] > size[temp]) {
		cout << "Fennec";
	}	else	{
		cout << "Snuke";
	}
}

Measured memory_bytes: 14336
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n, m = MI()
a = [LI() for _ in range(m)]
p = LI()
index = 0
cnt = 0
for i in range(2 ** n):
    # print("index = "+str(index))
    tento = [0] * n
    for j in range(n):
        if ((i >> j) & 1):
            tento[n-1-j] = 1
    index = 0
    for k in a:
        tmp = 0
        for i, num in enumerate(k[1:]):
            if tento[num-1] == 1:
                tmp += 1
        # 条件に当てはまる電球でついてるやつ
        if tmp % 2 == p[index]:
            index += 1
            if index == m:
                cnt += 1
        else:
            break
print(cnt)


Measured memory_bytes: 69740
#include <iostream>

using namespace std;

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

 int diff = a - b;
 if (diff < 0) diff = -diff;

 diff %= 2;

 if (diff == 0) cout << "Alice";
 else cout << "Borys";

 return 0;
}

Measured memory_bytes: 256