akhauriyash/Code-Regression huggingface dataset:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()

cnt = Counter(S)
ans = "Yes"
if not((cnt["N"]==0 and cnt["S"]==0) or (cnt["N"]>0 and cnt["S"]>0)):
    ans = "No"
if not((cnt["W"]==0 and cnt["E"]==0) or (cnt["W"]>0 and cnt["E"]>0)):
    ans = "No"

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 3316
class FenwickTree:
    """FenwickTree (Binary Indexed Tree, 0-index)

    Queries:
        1. add(i, val): add val to i-th value
        2. sum(n): sum(bit[0] + ... + bit[n-1])

    complexity: O(log n)

    See: http://hos.ac/slides/20140319_bit.pdf
    """

    def __init__(self, a_list):
        self.N = len(a_list)
        self.bit = a_list[:]
        for _ in range(self.N, 1 << (self.N - 1).bit_length()):
            self.bit.append(0)
        for i in range(self.N-1):
            self.bit[i | (i+1)] += self.bit[i]

    def add(self, i, val):
        while i < self.N:
            self.bit[i] += val
            i |= i + 1

    def sum(self, n):
        ret = 0
        while n >= 0:
            ret += self.bit[n]
            n = (n & (n + 1)) - 1
        return ret

    def query(self, low, high):
        return self.sum(high) - self.sum(low)


def yosupo():
    # https://judge.yosupo.jp/problem/point_add_range_sum
    N, Q = map(int, input().split())
    fwt = FenwickTree([int(x) for x in input().split()])
    for _ in range(Q):
        type_, l, r = map(int, input().split())
        print([fwt.sum(i) for i in range(N+1)])
        if type_ == 0:
            fwt.add(l, r)
        else:
            print(fwt.query(l, r))


def aoj():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_B
    N, Q = map(int, input().split())
    fwt = FenwickTree([0] * N)
    for _ in range(Q):
        type_, l, r = map(int, input().split())
        if type_ == 0:
            fwt.add(l-1, r)
        else:
            print(fwt.query(l-2, r-1))


if __name__ == "__main__":
    # yosupo()
    aoj()



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

#define int long long
using namespace std;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

signed main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    vector<int> diff(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    if (n == 1) {
        cout << abs(v[0] - x) << "\n";
        return 0;
    }
    int d = __gcd(abs(x - v[0]), abs(x - v[1]));
    for(int i = 2; i < n; ++i) {
        d = __gcd(d, abs(x - v[i]));
    }
    cout << d << "\n";
}

Measured memory_bytes: 1792
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

#define rep(i, n) for (long long i = 0; i < n; i++)

void solve() {
  ini(N);
  vll a(N);
  rep(i, N) cin >> a[i];

  vll bound = {0, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
  vll count(bound.size());
  rep(i, N) {
    rep(j, bound.size() - 1) {
      if (bound[j] <= a[i] && a[i] < bound[j + 1])
        count[j]++;
    }
    if (bound.back() <= a[i])
      count.back()++;
  }

  ll colors =
      count_if(count.begin(), count.end() - 1, [](auto x) { return x > 0; });
  out(max(1LL, colors), colors + count.back());
}


Measured memory_bytes: 3656
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int left = -1;
		int right = -1;
		int base = 0;
		long count = 0;
		for (int i = 0; i < n; i++) {
		    while(right < n - 1 && (base ^ arr[right + 1]) == (base + arr[right + 1])) {
		        right++;
		        base += arr[right];
		    }
		    count += right - i + 1;
		    base -= arr[i];
		}
	    System.out.println(count);
   }
}




Measured memory_bytes: 81888
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[102] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
        int b[102] = {};
        b[i] = a[i];
        z += a[i];
        for (int j = i + 1; j <= n; j++) b[j] = min(b[j - 1], a[j]);
        for (int j = i + 1; j <= n; j++) a[j] -= b[j];
    }
    cout << z;
}


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

typedef long long ll;

int main(){
    string a,b;

    cin >>a >> b;
    if(a.length() > b.length()){
        cout << "GREATER";
    }

    else if (a.length() < b.length()){
        cout << "LESS";
    }
    else {
        if(a>b){
            cout << "GREATER";
        }
        else if (a < b){
            cout << "LESS";
        }
        else cout << "EQUAL";

    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return res;
}
ll inv(ll x){
    return power(x,mod-2);
}
int main(){
    ll t,i;
    string s;
    cin>>s;
    for(i=0;i<3;i++)if(s[i]=='7'){cout<<"Yes";return 0;}
    cout<<"No";
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <set>
#include <queue>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
#define ps push_back 
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b;
	cin >> a >> b;
	cout << (a * a) - b << endl;
	return 0;
}

Measured memory_bytes: 256
x,n=gets.chomp.split(" ").map(&:to_i);
n = 0
begin
  fob_lis = gets.chomp.split(' ').map(&:to_i)
rescue
  fob_lis = []
end
lis = [*0..101]
lis = lis - fob_lis

sa_m = 100000
ans = 0
lis.each do |k|
  sa = (x - k).abs
  if sa < sa_m
    sa_m = sa
    ans = k
  end
end

puts ans

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

const ll MAX_S = 1e9;

int main(){
  
  ll N,K,S; cin >> N >> K >> S;
  
  for(ll i = 0; i < K; i++){ cout << S << " ";}
  for(ll i = 0; i < N-K;i++){ 
    if( S == MAX_S){ cout << S-1 << " ";}
    else{ cout << S+1 << " ";}
  }
  
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 1280
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
    
    private static BufferedReader br;
    private static StringTokenizer strz; 
    
	public static void main (String[] args) throws java.lang.Exception {
		br =  new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		strz = new StringTokenizer(br.readLine());
		
		long[] arr = new long[n];
		long xor = 0;
		
		for(int i = 0; i < n; ++i){
		    arr[i] = Long.parseLong(strz.nextToken());
		    xor ^= arr[i];    
		}
		
		for(int i = 0; i < n; ++i){
		    System.out.print((xor^arr[i]) + " ");
		}
	}
}

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int find(int x){
        if(d[x] < 0) return x;
        return find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n){
        int ans = uf.size(i) - 1 - deg[i];
        for(int u : to[i]){
            if(uf.same(i,u)) ans--;
        }
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
int k;
int mid;
string s;
int req;
int dp[20][10][2];
int solve (int idx,int prev,int flag){
    if(idx == req)
        return 1;
    if(dp[idx][prev][flag]!=-1)
        return dp[idx][prev][flag];
    int ans = 0;
    int l = max((int)0,prev-1);
    int r = min((int)9,prev+1);

    if(idx == 0){
        l = 1;
        r = 9;
    }
    int num = s[idx]-'0';
    if(!flag){
        r = min(r,num);
    }
    for(int i = l ; i<=r ; i++){
        if(i<num)
            ans+=solve(idx+1,i,1);
        else ans+=solve(idx+1,i,flag);
    }
    dp[idx][prev][flag] = ans;
    return ans;
}
signed main(){
    fast;
    cin>>k;
    int low = 1;
    int high = 1e18;
    int ans = -1;
    while(low<=high){
        mid = (low+high)/(int)2;
        s = to_string(mid);
        int n = (int)s.size();
        int cnt = 0;
        for(int len = 1;len<=n;len++){
            memset(dp,-1,sizeof(dp));
            req = len;
            if(len<n){
                cnt+=solve(0,0,1);
            }
            else cnt+=solve(0,0,0);
            //cout<<cnt<<" ";
        }
        //cout<<mid<<"->"<<cnt<<endl;
        if(cnt>=k){
            ans = mid;
            high = mid-1;
        }
        else{
            low = mid+1;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
r = [0] * (n)
for i in range(n):
    r[i] = int(input())
    
num_max = r[1] - r[0]
num_min = r[0]
min_idx = 0
for i in range(1, n):
    if num_max < r[i] - num_min:
        num_max = r[i] - num_min
    if r[i] < num_min:
        num_min = r[i]
print(str(num_max))


Measured memory_bytes: 13376
while 1:
	a,op,b= map(str,raw_input().split())
        a = int(a)
        b = int(b)

	if op=="+":
		x=a+b
	elif op=="-":
		x=a-b
	elif op=="*":
		x=a*b
	elif op=="/":
		x=a/b
	elif op=="?":
		break
	
	print "%d" %(x)

Measured memory_bytes: 6428
// https://atcoder.jp/contests/abc067/tasks/abc067_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
        cout << "Possible";
    } else {
        cout << "Impossible";
    }
    return 0;
}


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

using namespace std;

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

string s;

int calc(int x)
{
    int res = 0;
    reps(i, x, x+3) {
        res *= 10;
        res += s[i] - '0';
    }
    return res;
}

int main()
{
    cin >> s;
    int mi = 100000;
    rep(i, s.length() - 2) {
        int t = abs(calc(i) - 753);
        mi = min(mi, t);
    }
    cout << mi << endl;
}

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

using namespace std;



int main(){
  
 int n;
 cin>>n;
 vector<int> a;
  
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    
   a.push_back(x);
    
    
  }
  

  int dp[n];

  for(int i=0;i<n;i++){

      dp[i]=INT_MAX;

  }

    dp[0]=0;


  for(int i=0;i<n-1;i++){

      if(i+1<n){
        dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));

      }

      if(i+2<n){

          dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));

      }
  }

  cout<<dp[n-1];

  
  
 return 0;
  
  
}



Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
using ull = uint64_t;

ull ceil(ull a, ull b){
    return a / b + !!(a % b);
}

int main(){
    ull N, X;
    cin >> N >> X;
    ull x[N];
    for(ull i = 0; i < N; i++) cin >> x[i];
    ull sum[N + 1] = {};
    ull ans = UINT64_MAX;
    for(ull i = 0; i < N; i++) sum[i + 1] = sum[i] + x[i];
    for(ull cnt = 1; cnt <= N; cnt++){
        ull side = N;
        ull tmp = sum[N] - sum[N - cnt] + N * X + cnt * X;
        for(ull i = 1; side; i++){
            ull mv = min(side, cnt);
            tmp += ((sum[side] - sum[side - mv]) - (sum[side - mv] - sum[side < mv + mv ? 0 : side - mv - mv])) * (i + 1) * (i + 1);
            side -= mv;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int N, A, B;
    string S;
    cin >> N >> A >> B;
    cin >> S;
    int a = 0, b = 0;
    rep(i, N)
    {
        if (S[i] == 'a' && a + b < A + B)
        {
            cout << "Yes" << endl;
            a++;
        }
        else if (S[i] == 'b' && a + b < A + B && b < B)
        {
            cout << "Yes" << endl;
            b++;
        }
        else //if (S[i] == 'c')
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main (void){
    int n, o;
    scanf("%d", &n);
    if(n % 1000==0){
        o = 0;
    }else{
        o = ((n/1000)+1)*1000-n;
    }
    printf("%d\n", o);
    return 0;
}

Measured memory_bytes: 1720
n = int(input())
a, b, c = list(map(int, input().split()))

if n > 1:
    for _ in range(n-1):
        a_, b_, c_ = list(map(int, input().split()))
        a_ += max(b, c)
        b_ += max(a, c)
        c_ += max(a, b)
        a, b, c = a_, b_, c_

print(max(a, b, c))
"""
ちゃんと解いたVer
"""


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int a, b = 0, c = 0;
    for (int i = 0; i < 3; i++) {
        cin >> a;
        if(a==5)b++;
        else if(a==7)c++;
    }
    if(b==2 && c==1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;

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

    int num=0;
    int total=1;
    while(total < b){
        num++;
        total += a-1;
    }
    
    cout << num << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;

int main()
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H'){
		printf("%c\n",b);
	}
	else{
		if(b=='H'){
			printf("D\n");
		}
		else printf("H\n");
	}
}

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


int x;


bool judge(int m, int n, int l)
{
  long long sumv;
  
  sumv = 500*m + 100*n + 50*l;
  if ( sumv == x ) return true;
  else return false;
}


int main()
{
  int a, b, c, cnt=0;

  cin >> a >> b >> c >> x;

  for ( int i=0; i<a+1; i++ ) {
    for ( int j=0; j<b+1; j++ ) {
      for ( int k=0; k<c+1; k++ ) {
	if ( judge(i, j, k) ) cnt++;
      }
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum[100005];
ll tum[100005];
string S,T;
int q;
int main(){
  cin >> S >> T;
  for(int i=0;i<S.size();i++)
    sum[i+1] = sum[i] + (S[i]=='A'?1:2);
  for(int i=0;i<T.size();i++)
    tum[i+1] = tum[i] + (T[i]=='A'?1:2);

  cin >> q;
  for(int i=0;i<q;i++){
    int a,b,c,d; cin >> a >> b >> c >> d; --a; -- c;
    if( ( sum[b]-sum[a] ) % 3 == ( tum[d]-tum[c] ) % 3 )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}


Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;

class Sobaya
{
    static void Main(){
      new Sobaya().calc();
      return;
    }
      
    Scanner cin;
    
    void calc(){
        cin = new Scanner();
        int n = cin.nextInt();
        bool t = false;
        for(int i=1; i<10; i++){
            for(int j=1; j<10; j++){
                if(n==i*j) t=true;
            }
        }
        
        Console.WriteLine(t ? "Yes" : "No");

    }
}




class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d", &a,&b,&c);
   if(a>b&&b>c){
        printf("%d %d %d\n", c,b,a);
   }else if(b>c&&c>a){
        printf("%d %d %d\n", a,c,b);
   }else if(c>a&&a>b){
        printf("%d %d %d\n", b,a,c);
   }else if(c>b&&b>a){
        printf("%d %d %d\n", a,b,c);
   }else if(b>a&&a>c){
        printf("%d %d %d\n", c,a,b);
   }else if(a>c&&c>b){
        printf("%d %d %d\n", b,c,a);   
   }else if(b>c&&c==a){
        printf("%d %d %d\n", a,c,b);
   }else if(a>c&&c==b){
        printf("%d %d %d\n", b,c,a);
   }else if(b>a&&a==b){
        printf("%d %d %d\n", c,a,b);
   }
return 0;
}

Measured memory_bytes: 596
c[31],n,k,m,a,i,j;
main()
{
	scanf("%d%d",&n,&m);
	for(;i<n;i++)
	{
		scanf("%d",&k);
		for(j=0;j<k;j++)scanf("%d",&a),c[a]++;
	}
	for(a=i=0;i++<m;)a+=c[i]==n;
	printf("%d",a);
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
n = int(input())
h = [int(i) for i in input().split()]

dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[n - 1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

long long int gcd(long long int a,long long int b)
{
    long long int c;
    while (a != 0)
    {
        c = a;
        a = b % a;
        b = c;
    }
    return b;
}
int main()
{
    long long int n;
    cin >> n;

    REP(h, 1, 4000)
    {
        REP(w, 1, 4000)
        {
            long long int temp = 4 * h * w - n * (h + w);
            if (temp < 0)
                continue;

            //ユークリッド互除法で誤差を消す
            long long int foo = gcd(temp, n * h * w);
            if (temp == foo)
            {
                cout << h <<" "<< w <<" "<< ( n * h * w)/foo << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H') {
      cout << 'H';
    }
    else {
      cout << 'D';
    }
  }
  else {
    if (b == 'D') {
      cout << 'H';
    }
    else {
      cout << 'D';
    }
  }
}


Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  int n;
  int ans;
  string s;
  cin >> n;
  cin >> s;

  int n_R = 0;
  int n_G = 0;
  int n_B = 0;

  REP(i, n) {
    if (s[i] == 'R') {
      n_R += 1;
    }
    if (s[i] == 'G') {
      n_G += 1;
    }
    if (s[i] == 'B') {
      n_B += 1;
    }
  }

  ans = n_R * n_G * n_B;

  REPS(i, (n - 1) / 2) {
    REP(j, n - i * 2) {
      if (s[j] != s[j + i] && s[j] != s[j + i * 2] &&
          s[j + i] != s[j + i * 2]) {
        ans -= 1;
      }
    }
  }

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


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i, a, b) for(int i=(int)(a); i>=(int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 1LL << 55
typedef long long ll;
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;}

using namespace std;

ll a[444];
bool flag[444][444];
ll cum[444];
ll dp[444][444];

ll f(int l, int r)
{
	if(flag[l][r])return dp[l][r];
	flag[l][r] = true;
	if(l>=r)return 0;
	ll fans=INF;
	REP(i, l, r){
		chmin(fans, f(l, i)+f(i+1, r));
	}
	return dp[l][r] = fans + cum[r]-cum[l-1];
}

int main(void)
{
	int N;
	cin >> N;
	REP(i, 1, N+1){
		cin >> a[i];
	}
	cum[0] = 0;
	REP(i, 1, N+1){
		cum[i] = cum[i-1] + a[i];
	}
	cout << f(1, N) << "\n";
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  char S[4];
  int k,judge=0;
  scanf("%s",S);
  if(S[0]==S[1]&&S[1]==S[2]) puts("Yes");
  else if(S[1]==S[2]&&S[2]==S[3]) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int a, n[105],s = 1,s2=1; 
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> n[i];
	}
	for (int i = 0; i < a; i++)
	{
		s = s*3;
		if (n[i] % 2 == 0) s2 = s2 * 2;

	}
	cout << s - s2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

int main()
{
    int d, t, s;
    cin >> d >> t >> s;

    if (s * t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>

int main()
{
	int n;
	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			std::cout << " " << i;
		}
		else do {
			if (x % 10 == 3) {
				std::cout << " " << i;
				break;
			}
			x /= 10;
		} while (x);
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 3092
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	N, K := nextInt(), nextInt()
	// N, K := 3, 2
	count := 0
	for i := K; i <= N+1; i++ {
		min := i * (i - 1) / 2
		max := i * (2*N - i + 1) / 2
		count += max - min + 1
		count %= pow(10, 9) + 7
	}
	fmt.Println(count)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1760
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int K = array[1];
            int[] H = readIntArray(reader);

            int ans = 0;
            for (int i = 0; i < N; i++) {
                if (H[i] >= K) {
                    ans++;
                }
            }

            System.out.println(ans);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

}


Measured memory_bytes: 32980
H, W = map(int, input().split())
ans = 10**10
for i in range(1,H-1):
    h2 = (i+H)//2
    s1 = W*i
    s2 = W*(h2-i)
    s3 = W*(H-h2)
    tmp = max(s1,s2,s3) - min(s1,s2,s3)
    ans = min(tmp, ans)
    w = W//2
    s2 = (H-i) * w
    s3 = (H - i) * (W-w)
    tmp = max(s1,s2,s3) - min(s1,s2,s3)
    ans = min(tmp, ans)
for i in range(1,W):
    w2 = (W + i)//2
    s1 = i*H
    s2 = (w2-i)*H
    s3 = (W-w2)*H
    tmp = max(s1,s2,s3) - min(s1,s2,s3)
    ans = min(tmp, ans)

    h = H//2
    s2 = h * (W-i)
    s3 = (H-h) * (W-i)
    tmp = max(s1,s2,s3) - min(s1,s2,s3)
    ans = min(tmp, ans)
print(ans)

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

int main()
{
    int N;
    cin >> N;
    vector<int> s(N);
    for (int i = 0; i < N; i++)
        cin >> s[i];
    int sum = 0;
    vector<int> t;
    for (int i = 0; i < N; i++)
    {
        sum += s[i];
        if (s[i] % 10 != 0)
            t.push_back(s[i]);
    }
    sort(t.begin(), t.end());
    if (sum % 10 != 0)
    {
        cout << sum << endl;
    }
    else
    {
        if (t.size() != 0)
            sum -= t[0];
        else
            sum = 0;
        cout << sum << endl;
    }
    return 0;
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

string input[10] = {
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	int t; cin >> t;
	while(t --) {
		string s; cin >> s;
		string t = "";
		for(char c : s)
			if(c == '0') {
				if(t.size()) {
					int l = input[t[0] - '0'].size();
					cout << input[t[0] - '0'][(t.size() - 1) % l];
					t = "";
				}
			} else
				t += c;
		cout << '\n';
	}

	return 0;
}

Measured memory_bytes: 2984
#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 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(){
    ll n,m;
    cin>>n>>m;
    lvec a(n,1);
    plvec p(m);
    set<ll> st;
    st.insert(0);
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        p[i]=make_pair(x,y);
        a[x]--;
        a[y]++;
        if(st.count(x)){
            st.insert(y);
            if(a[x]==0) st.erase(x);
        }
    }
    cout<<st.size()<<endl;
}

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

using ll = long long;

ll dp[60][60 * 60];

int main() {
    int N, A;
    cin >> N >> A;

    vector<int> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    int X = accumulate(x.begin(), x.end(), 0);

    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int num = N; num >= 0; num--) {
            for (int sum = 0; sum <= X; sum++) {
                if (num - 1 >= 0 && sum - x[i] >= 0) {
                    dp[num][sum] += dp[num - 1][sum - x[i]];
                }
            }
        }
    }
    ll ans = 0;
    for (int num = 1; num <= N; num++) {
        ans += dp[num][A * num];
    }
    cout << ans << endl;

    return 0;
}


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

vector<int> v1[200100], v2[200100];
int comp[200100]={0}, comp2[200100];
int sz[200100]={0}, sz2[200100];
int vis[200100]={0};
void dfs(int x){
	vis[x] = 1;
	sz[comp[x]]++;
	for(int j=0; j<v1[x].size(); j++){
		if(vis[v1[x][j]])continue;
		comp[v1[x][j]] = comp[x];
		dfs(v1[x][j]);
	}		
}
vector<pair<int, int> > c[200100];
void dfs1(int x){
        vis[x] = 1; 
	c[comp2[x]].push_back({comp[x], x});
        sz2[comp2[x]]++;
        for(int j=0; j<v2[x].size(); j++){
                if(vis[v2[x][j]])continue;
                comp2[v2[x][j]] = comp2[x];
                dfs1(v2[x][j]);
        } 
}


int main(){
	int n, k, l; cin>>n>>k>>l;
	for(int i=1; i<=k; i++){
		int x, y;cin>>x>>y;
		v1[x].push_back(y);
		v1[y].push_back(x);
	}
	int cnt = 1;
	for(int i=1; i<=n; i++)
	if(!vis[i]){
		comp[i] = cnt++;
		dfs(i);
	}
	memset(vis, 0, sizeof(vis));
	for(int i=1; i<=l; i++){
		int x, y;cin>>x>>y;
		v2[x].push_back(y);
		v2[y].push_back(x);
	}
	cnt = 1;
	for(int i=1; i<=n; i++){
		if(!vis[i]){
			comp2[i] = cnt++;
			dfs1(i);
		}
	}
	int freq[200100]={0};
	int ans[200100];
	for(int i=1; i<cnt; i++){	
		sort(c[i].begin(),c[i].end());
		int f=1;
		for(int j=1; j<c[i].size(); j++){
			if(c[i][j].first == c[i][j-1].first)f++;
			else{
				freq[c[i][j-1].first]=f;
				f=1;		
			}
		}
		freq[c[i].back().first]=f;
		for(int j=0; j<c[i].size(); j++){
			ans[c[i][j].second] = freq[c[i][j].first];
		}
	}
	for(int i=1; i<=n ;i++)cout<<ans[i]<<" ";cout<<endl;
	return 0;
}


Measured memory_bytes: 29812
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


bool is_prime[1000000];

int cnt[1000000];

int main() {
	//PLAY();


	for (int i = 2; i < 1000000; i++)
		is_prime[i] = true;


	for (int i = 2; i < 1000000; i++){
		if (is_prime[i]) {
			for (int j = i * 2; j < 1000000; j += i)
				is_prime[j] = false;
		}
	}
	for (int i = 1; i < 1000000; i++) {
		if (is_prime[i] && is_prime[(i + 1) / 2])
			cnt[i] = 1;
	}
	for (int i = 1; i < 1000000; i++)
		cnt[i] += cnt[i - 1];
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << cnt[r] - cnt[l - 1] << "\n";
	}
	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,p,flg[100001],cnt[100001],ac,wa,i;
	string s;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	{
		flg[i]=0;	cnt[i]=0;
	}
	for(i=0;i<m;i++)	{
		scanf("%d",&p);
		cin >>s;
		if(flg[p]==0)	{
			if(s=="WA")	cnt[p]++;
			else flg[p]=1;
		}
	}
	ac=0;	wa=0;
	for(i=1;i<=n;i++)	{
		ac+=flg[i];
		if(flg[i]==1)	wa+=cnt[i];
	}
	printf("%d %d\n",ac,wa);
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//-2のn乗を返す
ll func(ll n){
  if(n == 0) return 1;
  ll res = -2;
  rep(i, n-1)
    res *= -2;
  
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<pll> vc;

  if(n == 0) cout << 0 << ln;
  else{
  bool f = false; int cnt = 0;
  ll plus = 0, minus = 0;
  while(!f){
    ll num = func(cnt);
    if(cnt%2 == 0){
     plus += num; 
     pll p(plus, plus - num + 1);
     vc.push_back(p);
     if(n <= plus && n >= plus - num + 1) f = true;
    }else{
      minus += num;
      pll p(minus - num - 1, minus);
      vc.push_back(p);
      if(n >= minus && n <= minus - num - 1) f = true;
    }
    cnt++;
  }

  string res;
  for(int i = cnt - 1; i >= 0; i--){
    //cout << "n:" << n << ln;
    ll mx = vc[i].first; ll mn = vc[i].second;
    if(n <= mx & n >= mn){
      res += "1";
      n -= func(i);
    } else{
      res += "0";
    }
  }
   cout << res << ln;
  }
}
  


Measured memory_bytes: 256
/* author:hellojim */
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int x;
	cin>>x;
	cout<<(x^1)<<endl; 
	return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

int A[100000], n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;

    while(left<right){
        mid = (left+right)/2;
        if(key==A[mid]) return 1;
        if(key>A[mid]) left = mid+1;
        else if(key < A[mid]) right = mid;
    }

    return 0;
}

int main(){
    int i,q,k,sum=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d", &q);
    for(i=0;i<q;i++){
        scanf("%d", &k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n",sum);

    return 0;
}


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

map<int,int>mp;

int count(int x) {
    if (mp.count(x) == 0) return 0;
    return mp[x];
}    

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

    for(int i=0;i<n;i++){
        int a;cin>>a;mp[a]++;
    }
    int ans=0;
    for(auto it=mp.begin();it!=mp.end();it++){
        int x;
        x=it->first;
        ans=max(ans,count(x)+count(x-1)+count(x+1));
        ans=max(ans,count(x-1)+count(x-2)+count(x));
        ans=max(ans,count(x+1)+count(x)+count(x+2));
    }
    cout<<ans<<endl;
}

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

int main () {
  int n, l; cin >> n >> l;
  
  string s[n];
  for (int i=0; i<n; i++) cin >> s[i];
  sort(s, s+n);
  
  string str;
  for (int i=0; i<n; i++)    str += s[i];
  
  cout << str << endl;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
    int n, q;
    string s;
    cin >> n >> s >> q;
    map<char, set<int>> char_index_dict;
    for (int i = 0; i < s.length(); i++) {
        char_index_dict[s[i]].insert(i);
    }
    vector<string> types(q), As(q), Bs(q);
    for (int i = 0; i < q; i++) {
        cin >> types[i] >> As[i] >> Bs[i];
    }    
    for (int i = 0; i < q; i++) {
        int type = stoi(types[i]);
        if (type == 1) {
            int a = stoi(As[i]) - 1;
            char b = Bs[i][0];
            if (s[a] != b) {
                char_index_dict[s[a]].erase(a);
                s[a] = b;
                char_index_dict[s[a]].insert(a);
            }
            // cout << s << endl;
        } else {
            int a = stoi(As[i]) - 1;
            int b = stoi(Bs[i]) - 1;

            int ans = 0;
            for (char c = 'a'; c <= 'z'; c++) {
                auto beg_ptr = char_index_dict[c].lower_bound(a);
                auto end_ptr = char_index_dict[c].lower_bound(b + 1);
                if (end_ptr == char_index_dict[c].end()) {
                    if (beg_ptr != char_index_dict[c].end()) {
                        ans += 1;
                    }
                } else {                    
                    if (*beg_ptr != *end_ptr) {
                        ans += 1;
                    }
                }
                // int beg = distance(char_index_dict[c].begin(), char_index_dict[c].lower_bound(a));
                // int end = distance(char_index_dict[c].begin(), char_index_dict[c].lower_bound(b + 1));
                // cout << a << b << c << ", " << beg << " - " << end << endl;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 29444
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fr(a,b) for(int i=a;i<b;i++)
#define frn(a,b) for(int i=a;i>=b;i--)

int32_t main(){
	int k,a,b;
	cin>>k>>a>>b;
	int ans = 0;
	fr(a,b+1) if(i%k == 0 )ans =1;
	if(ans == 0) cout<<"NG";
	else cout<<"OK";
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>


using namespace std;

#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) repi(i,0,n)
#define mp make_pair
#define pb push_back

struct term {
  int ts, te, n, m;
};
int main()
{
  int N, M;
  while(cin >> N >> M, N||M) {
    int r;
    cin >> r;
    map<pair<int, int>, int> table;
    vector<term> v;
    rep(i, r) {
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      m--; n--;
      if(s == 1) table[mp(n, m)] = t;
      else {
	v.pb((term){table[mp(n, m)], t, n, m});
      }
    }
    //    cout << "term" << endl;
    rep(i, v.size()) {
      //      cout << v[i].ts << " " << v[i].te << " " << v[i].n << " " << v[i].m << endl;
    }
    int q;
    cin >> q;
    //    cout << endl;
    rep(i, q) {
      int l, r, m;
      cin >> l >> r >> m;
      m--;
      int ans = 0;
      vector<int> s(1261);
      rep(j, v.size()) if(v[j].m == m){
	s[v[j].ts] += 1;
	s[v[j].te] -= 1;
      }
      rep(j, 1260) s[j+1] += s[j];
      repi(j, l, r) if(s[j]) ans++;
      cout << ans << endl;
    }

  }
  return 0;
}

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

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

ll N, Z, W;
ll ans = 0;

void solve() {
    cin >> N >> Z >> W;
    ll a[N];
    rep(i,N) cin >> a[i];
    if (N == 1) {
        cout << abs(a[0] - W) << endl;
        return;
    }
    int cur = 0;
    ll A = Z, B = W;
    for (int t = 0;;++t) {
        ll m;
        if (t % 2 == 0) m = 0;
        else m = (ll)1e9;
        int m_i = cur;
        for (int i = cur; i < N-1; ++i) {
            if (t % 2 == 0 && abs(a[cur] - a[N-1]) > m) {
                m = abs(a[cur] - a[N-1]);
                m_i = i;
            } else if (t % 2 == 1 && abs(a[cur] - a[N-1]) < m) {
                m = abs(a[cur] - a[N-1]);
                m_i = i;
            }
        }
        if (t % 2 == 0) A = a[m_i];
        else B = a[m_i];
        cur = m_i + 1;
        if (cur == N-1) {
            if (t % 2 == 0) B = a[N-1];
            else A = a[N-1];
            break;
        }
    }
    cout << max(abs(A - B), abs(a[N-1] - W)) << endl;
}

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


Measured memory_bytes: 256