akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    x.push_back(X);

    vector<int> y(M);
    for (int i = 0; i < M; i++) cin >> y[i];
    y.push_back(Y);

    bool good = false;
    for (int z = -100; z <= 100; z++) {
        bool b = true;
        for (int i = 0; i < N+1; i++) if (x[i] >= z) b = false;
        for (int i = 0; i < M+1; i++) if (y[i] < z) b = false;
        if (b) good = true;
    }

    if (good) cout << "No War";
    else cout << "War";

    return 0;
}











































































Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

struct point {
	double x, y;
}p[5];

double dis(point A, point B) {
	return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}

double crossProd(point A, point B, point C) {
	return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}

int cmp(const void *a, const void *b) {
	point *c = (point *)a;
	point *d = (point *)b;
	double k = crossProd(p[0], *c, *d);
	if (k < 0 || !k && dis(p[0], *c) > dis(p[0], *d)) return 1;
	return -1;
}

bool solve() {
	double x = p[0].x;
	double y = p[0].y;
	int mi = 0;
	for (int i=1; i<4; ++i) {
		if (p[i].y < y || p[i].y == y && p[i].x < x) {
			x = p[i].x;
			y = p[i].y;
			mi = i;
		}
	}
	point tmp = p[0];
	p[0] = p[mi];
	p[mi] = tmp;
	qsort(p, 4, sizeof(point), cmp);
	if (crossProd(p[0], p[1], p[2]) > 0 &&
		crossProd(p[1], p[2], p[3]) > 0 &&
		crossProd(p[2], p[3], p[0]) > 0) return true;
	return false;
}

int main() {
	while (scanf("%lf,%lf", &p[0].x, &p[0].y) != EOF) {
		for (int i=1; i<4; ++i) scanf (",%lf,%lf", &p[i].x, &p[i].y);
		bool yes = solve();
		if (yes) printf ("YES\n");
		else printf ("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string s, t;
    cin >> s >> t;
    int ans = 0;
    REP(i, 0, s.size())
    if (s[i] != t[i])++ ans;
    cout << ans << endl;
}


Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

typedef long long ll;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for(int i = 1; i < n; i++) {
    for(int j = i + 1; j <= n; j++) {
      int ijxor = (i ^ j);
      int ans = 1;
      while((ijxor & 1) == 0) {
        ans++;
        ijxor = ijxor >> 1;
      }
      cout << ans << " ";
    }
    cout << "\n";
  }
  return 0;
}



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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int h, w, k;
  char c[10][10];
  cin>>h>>w>>k;
  REP(i, h){
    REP(j, w){
      cin>>c[i][j];
    }
  }
  int ans=0;
  REP(i, 1<<h){
    REP(j, 1<<w){
      int tc[10][10];
      REP(x, h){
        REP(y, w){
          tc[x][y]=c[x][y];
        }
      }
      REP(a, h){
        if(i>>a&1){
          REP(y, w){
            tc[a][y]='.';
          }
        }
      }
      REP(b, w){
        if(j>>b&1){
          REP(x, h){
            tc[x][b]='.';
          }
        }
      }
      int tmp=0;
      REP(x, h){
        REP(y, w){
          if(tc[x][y]=='#'){
            ++tmp;
          }
        }
      }
      if(tmp==k){
        ++ans;
      }
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> data;
  REP(i, n) {
    int x;
    cin >> x;
    data.push_back(x);
  }
  sort(ALL(data));
  int ans = 0;
  REP(i, k) { ans += data[i]; }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;
int a[N],mx1[N],mx2[N];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    mx1[0]=a[0];
    for(int i=1;i<n;i++)
        mx1[i]=max(mx1[i-1],a[i]);
    mx2[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
        mx2[i]=max(mx2[i+1],a[i]);
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            cout<<mx2[i+1]<<endl;
            continue;
        }
        if(i==n-1)
        {
            cout<<mx1[i-1]<<endl;
            continue;
        }
        cout<<max(mx1[i-1],mx2[i+1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 3968
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <utility>

using namespace std;

int main() {
  int n;

  cin >> n;

  switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
  }

  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll W,H; cin >> W >> H;
  
  ll a = W+1; 
  ll b = H+1;
  
  vector<pair<ll,ll>> edge;
  
  for(ll i = 0; i < W; i++){
    ll p; cin >> p; edge.push_back({p,1});
    // 1 は x方向を意味
  }
  
  for(ll j = 0; j < H; j++){
    ll q; cin >> q; edge.push_back({q,2});
  }
  
  sort(edge.begin(),edge.end());
  
 
  ll itr = 0; 
  
  ll ans = 0; ll cnt = 0;
  
  while(true){
    
    ll cost = edge[itr].first;
    ll dir = edge[itr].second;
    
    if( dir == 1 && a > 0){ 
      ans += cost*b; cnt += b; a--; 
    }
    if( dir == 2 && b > 0){
      ans += cost*a; cnt += a; b--;
    }
    
    if( cnt >= (W+1)*(H+1)-1){break;}
       
    itr++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6512
# coding utf-8
N, K, Q = input().split()
N, K, Q = int(N), int(K), int(Q)

points = [K-Q for _ in range(N)]
for q in range(Q):
    collect = int(input()) - 1
    points[collect] += 1
for p in points:
    if p>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 7916
from collections import namedtuple
Node = namedtuple('Node', ['p', 'left', 'right'])

def insert(T, z):
    p = None
    x = T['root']
    while x != None:
        p = x
        if z < x: x = T[x].left
        else    : x = T[x].right

    T[z] = Node(p, None, None)

    if p == None:
        T['root'] = z
    elif z < p: T[p] = Node(T[p].p, z, T[p].right)
    else      : T[p] = Node(T[p].p, T[p].left, z)

 
def getInorderList(T, i):
    l = T[i].left
    r = T[i].right
    if l: yield from getInorderList(T, l)
    yield i
    if r: yield from getInorderList(T, r)


def getPreorderList(T, i):
    l = T[i].left
    r = T[i].right
    yield i
    if l: yield from getPreorderList(T, l)
    if r: yield from getPreorderList(T, r)


if __name__=='__main__':
    m = int(input())

    T = {}
    T['root'] = None
    for _ in range(m):        
        op = input().split()
        if op[0] == 'insert': insert(T, int(op[1]))
        else:
            print("",*getInorderList(T, T['root']))
            print("",*getPreorderList(T, T['root']))

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

int main() {
    long n, ave, ans = 0;
    cin >> n >> ave;
    vector<long> x(n);
    vector<vector<vector<long>>> dp(n + 1, vector<vector<long>>(n + 1, vector<long>(50 * n + 1, 0)));
    dp.at(0).at(0).at(0) = 1;
    rep(i, n) cin >> x.at(i);
    rep(i, n) rep(j, n) rep(k, 50 * n + 1) {
        dp.at(i + 1).at(j).at(k) += dp.at(i).at(j).at(k);
        if(k + x.at(i) <= 50 * n) dp.at(i + 1).at(j + 1).at(k + x.at(i)) += dp.at(i).at(j).at(k);
    }
    rep(i, n) ans += dp.at(n).at(i + 1).at((i + 1) * ave);
    cout << ans << endl;
}

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

int main() {

  while( true ) {

    long long int n;
    string t;
    cin >> n >> t;
    if ( n == 0 ) break;

    vector< pair< long long int, vector< long long int > > > v;

    for ( long long int i = 0; i < ( 1 << ( t.size() - 1 ) ); i++ ) {

      long long int s = 0;
      vector< long long int > p;


      long long int x = t[0] - '0';
      long long int bit = 1;
      for ( long long int j = 1; j < t.size(); j++ ) {
	if ( ( i & bit ) != 0 ) {
	  s += x;
	  p.push_back( x );
	  x = 0;
	}
	x = x * 10 + t[j] - '0';
	bit *= 2;
      }
      s += x;
      p.push_back( x );


      if ( s <= n ) {
	v.push_back( make_pair( s, p ) );
      }

    }

    sort( v.begin(), v.end() );
    if ( v.size() == 0 ) {
      cout << "error" << endl;
    }else if ( v.size() > 1 && ( v[ v.size() - 1 ].first == v[ v.size() - 2 ].first ) ) {
      cout << "rejected" << endl;
    }else {
      cout << v[ v.size() - 1 ].first;
      for ( long long int i = 0; i < v[ v.size() - 1 ].second.size(); i++ ) {
	cout << " " << v[ v.size() - 1 ].second[i];
      }
      cout << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 1240
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

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

int main() {
    string s;
    cin >> s;
    map<char, int> map;
    REP(i, s.size()) {
        map[s[i]]++;
    }

    bool f = false;
    FOR(i, map) {
        if(i->second > 1) {
            f = true;
            break;
        }
    }

    if(f) cout << "no" << endl;
    else cout << "yes" << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        int a[n],i,j,b[n];
        for(i=0;i<n;i++) {
                scanf("%d",&a[i]);
                b[i]=a[i];
        }
        sort(a,a+n);
        j=0;
        for(i=0;i<n;i++)
        {
            if(a[i]!=b[i])
                j++;
        }
        if(j>2) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,k;

    vi a;
    cin>>n;
    x = 0;
    in(a,n);
    ll b[3];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                b[0] = a[i];
                b[1] = a[j];
                b[2] = a[k];
                sort(b,b+3);
                if((b[0]==b[1])||(b[1]==b[2]))continue;
                if(b[0]+b[1]>b[2])x++;
            }
        }
    }
    cout<<x;


    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

template<class T> inline bool chmax(T& a, T b) {
    // chmax: change maximum
    // a より b の方が大きかったら，a の値を b の値に置き換える．
    // 書き換えた場合，true を返す
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];
    
    // calculation
    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    
    for (ll i = 0; i < N; ++i) {
        for (ll sum_w = 0; sum_w <= W; ++sum_w) {
            // 品物 i を選ぶ時
            if (sum_w - w[i] >= 0) chmax(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            
            // 品物 i を選ばない時
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    
    cout << dp[N][W] << "\n";
    
    return 0;
}

Measured memory_bytes: 80256
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		double r = stdIn.nextDouble();
		
		System.out.printf("%.6f %.6f",r*r*Math.PI,r*2*Math.PI);
	}

}

Measured memory_bytes: 18904
import java.util.Scanner;

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

    long M = 1_000_000_007;
    char[] l = scanner.next().toCharArray();
    int n = l.length;
    long[][] dp = new long[n + 1][2];
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      if (l[i - 1] == '0') {
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = dp[i - 1][1] * 3 % M;
      } else {
        dp[i][0] = dp[i - 1][0] * 2 % M;
        dp[i][1] = dp[i - 1][1] * 3 % M;
        dp[i][1] += dp[i - 1][0];
        if (dp[i][1] >= M) dp[i][1] -= M;
      }
    }
    System.out.println((dp[n][0] + dp[n][1]) % M);
  }
}


Measured memory_bytes: 30684
N = int(input())
 
d = {}
for i in range(2,N+1):
    tmp = i
    for j in range(2,N+1): 
        while tmp%j==0:
            tmp //= j
            d[j] = d.get(j,0)+1
            
ans = 1
for k in d:
    ans *= d[k]+1
    ans %= 10**9+7
print(ans)


Measured memory_bytes: 3060
n, m = map(int, input().split())

a = []
b = []

for i in range(m):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

ans = 0

for i in range(n):
    ans += a.count(i + 1)
    ans += b.count(i + 1)

    print(ans)
    ans = 0


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

int main() {
  string S;
  
  cin >> S;
  
  if(S == "SUN"){
    
    cout << 7 << endl;
  }
  else if(S == "MON"){
    
    cout << 6 << endl;
}
  else if(S == "TUE"){
    
    cout << 5 << endl;
}
   else if(S == "WED"){
    
    cout << 4 << endl;
} 
    else if(S == "THU"){
    
    cout << 3 << endl;
}
    else if(S == "FRI"){
    
    cout << 2 << endl;
}
    else{
    cout << 1 << endl;
}
  
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	if (n == 25)puts("Christmas");
	if (n == 24)puts("Christmas Eve");
	if (n == 23)puts("Christmas Eve Eve");
	if (n == 22)puts("Christmas Eve Eve Eve");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    ans += a >= k;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
n,m,l=map(int,input().split())
a=[[int(_) for _ in input().split()] for i in range(n)]
b=[[int(_) for _ in input().split()] for i in range(m)]
c=[[0]*l for _ in range(n)]
for i in range(n):
 for j in range(l):
  for k in range(m):
   c[i][j]+=a[i][k]*b[k][j]
for i in range(n):
 print(*c[i])

Measured memory_bytes: 7044
s, p = STDIN.read.split("\n")
s.size.times do |i|
  if s[i] == p[0]
    j = i
    ok = true
    p.size.times do |k|
      if s[j] != p[k]
        ok = false
        break
      end
      j = (j + 1) % s.size
    end
    if ok
      puts "Yes"
      exit
    end
  end
end
puts "No"

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,m,query;
  cin>>n>>m>>query;
  vector<int> l(m);
  vector<int> r(m);
  vector<int> p(query);
  vector<int> q(query);
  int i,j;
  rep(i,m)cin>>l[i]>>r[i];
  rep(i,query)cin>>p[i]>>q[i];
  vector<vector<int>> ls(n,vector<int>(n,0));
  rep(i,m)ls[l[i]-1][r[i]-1]++;
  vector<vector<int>> sum(n,vector<int>(n+1,0));
  rep(i,n)rep(j,n)sum[i][j+1]=sum[i][j]+ls[i][j];
  rep(i,query)
  {
    int ans=0;
    for(j=p[i]-1;j<=q[i]-1;j++)
    {
      ans+=sum[j][q[i]]-sum[j][p[i]-1];
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 5248
#include<stdio.h>

int main(){
  int i,n,s,d,m,j,k;
  unsigned char num[2][200];
  scanf("%d",&n);
  scanf("%d",&m);
  n*=2;
  for(i=0;i<n;i++)
    num[0][i]=i+1;
  for(i=0,s=0,d=1;i<m;i++,s=(s+1)%2,d=(d+1)%2){
    scanf("%d",&j);
    if(j==0){
      n/=2;
      for(j=0;j<n;j++){
	num[d][2*j]=num[s][j];
	num[d][2*j+1]=num[s][j+n];
      }
      n*=2;
    }else{
      for(k=0;k<j;k++){
	num[d][k+(n-j)]=num[s][k];
      }
      for(k=j;k<n;k++){
	num[d][k-j]=num[s][k];
      }
    }
  }
  for(j=0;j<n;j++){
    printf("%d\n",num[s][j]);
  } 
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int A[100010];
int N,S;

int main(){
	cin >> N;
	repp(i,0,N){
		cin >> A[i+1];
		S += abs(A[i+1] - A[i]);
	}
	S += abs(A[N]);
	repp(i,1,N+1) cout << S - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]) << endl;
	return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
   	public long knapsack(int n, int capacity, int[] weights, long[] values) {
        long[][] dp = new long[n + 1][capacity + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= capacity; j++) {
                long skip = dp[i - 1][j];
                long take = 0;
                if (weights[i - 1] <= j) {
                    take = dp[i - 1][j - weights[i - 1]] + values[i - 1];
                }
                dp[i][j] = Math.max(skip, take);
            }

        }
        return dp[n][capacity];
    }
    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String[] split = br.readLine().split(" ");
            int n = Integer.parseInt(split[0]);
            int w = Integer.parseInt(split[1]);
          	int[] weights = new int[n];
          	long[] values = new long[n];
            for (int i = 0; i < n; i++) {
                split = br.readLine().split(" ");
                weights[i] = Integer.parseInt(split[0]);
                values[i] = Long.parseLong(split[1]);
            }
          	Main app = new Main();
            long result = app.knapsack(n, w, weights, values);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 125520
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int D_MAX_V=210;
const int D_v_size=210;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
int d[120];
int e[120];
int g[120][120];
int main(){
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c)){
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++)g[i][j]=999999999;
			g[i][i]=0;
		}
		for(int i=0;i<b;i++){
			int p,q,r;scanf("%d%d%d",&p,&q,&r);
			p--;q--;
			g[p][q]=g[q][p]=min(g[p][q],r);
		}
		for(int k=0;k<a;k++)for(int i=0;i<a;i++)for(int j=0;j<a;j++)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
		int s=a*2;
		int t=a*2+1;
		for(int i=0;i<210;i++){
			D_G[i].clear();
			D_level[i]=D_iter[i]=0;
		}
		for(int i=0;i<a;i++){
			scanf("%d",d+i);
		}
		for(int i=0;i<a;i++){
			scanf("%d",e+i);
		}
		for(int i=0;i<a;i++){
			add_edge(s,i,d[i]);
			add_edge(a+i,t,e[i]);
		}
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)if(g[i][j]<c)add_edge(i,a+j,d[i]);
		printf("%d\n",max_flow(s,t));
	}
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,f[500000],sum,len,mon;
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++) cin>>f[i];
	for(int i=1;i<=n-1;i++)
	{
		len=f[i+1]-f[i];
		mon=len*a;
		if(mon<b) sum+=mon;
		else sum+=b;
	}
	cout<<sum;
	return 0; 
}

Measured memory_bytes: 1024
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:
            return INF
    ret1 = dfs(cur+1, a, b, c)
    ret2 = dfs(cur+1, a+L[cur], b, c) + 10
    ret3 = dfs(cur+1, a, b+L[cur], c) + 10
    ret4 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret1, ret2, ret3, ret4)

print(dfs(0,0,0,0))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String temp = sc.nextLine();
        int n = Integer.parseInt(temp);
        int s = 0;
        String orary = "";
        for (int i = 0; i < temp.length(); i++) {
            s += temp.charAt(i) - '0';
        }

        if (n % s == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


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

int main() {
  long long W, H, x, y;
  cin >> W >> H >> x >> y;
  double ans = double(W) * double(H) / 2;
  int ans2;

  if (x * 2 == W && y * 2 == H) {
    ans2 = 1;
  } else {
    ans2 = 0;
  }
  cout << ans << " " << ans2 << endl;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)

int main()
{
    int N, M = 0;
    cin >> N >> M;
    vector<int> S(M, 0);
    vector<int> ans(N, 0);
    vector<int> C(M, 0);

    rep(i, M)
    {
        cin >> S.at(i) >> C.at(i);
    }

    rep(i, M)
    {
        rep2(j, i + 1, M)
        {
            if (S.at(i) == S.at(j) & C.at(i) != C.at(j))
            {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    if (N >= 2)
    {
        rep(i, M)
        {
            if (S.at(i) == 1 & C.at(i) == 0)
            {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    rep(i, M)
    {
        ans.at(S.at(i) - 1) = C.at(i);
    }
      if (N > 1 & ans.at(0) == 0)
    {
        ans.at(0) = 1;
    }

    rep(i, N)
    {
        cout << ans.at(i);
    }


    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

ll f(ll n) {
	//1^2^3^4…^n
	switch(3 & n) {
	case 0: return n;
	case 1: return 1;
	case 2: return n + 1;
	case 3: return 0;
	}
	assert(false);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	ll ans = f(a - 1) ^ f(b);
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define inf 0x3f3f3f3f 
#define il inline 

#define in1(a) a=read()
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
#define out(a) printf( "%d" , a ) 
#define outn(a) out(a),putchar('\n')

#define I_int int 
inline I_int read() {

    I_int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) {
        if( c == '-' ) f = -1 ;
        c = getchar() ;
    }
    while( c >= '0' && c <= '9' ) {
        x = (x << 1) + (x << 3) + c - 48 ;
        c = getchar() ;
    }
    return x * f ;
}
#undef I_int

using namespace std ;

#define N 100010

int x , y ;

int main() {
	in2( x , y ) ;
	y /= 2 ;
	printf( "%d\n" , x + y ) ;
}

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

int main(){
	long long W,H,x,y;
	cin >>W>>H>>x>>y;
	double S=W*H/2.0;
	bool pro=false;
	if(2.0*x==W && 2.0*y==H){
		pro =true;
	}
	cout << S<<' '<<pro<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli; 
char grid[10][10];
lli n , m;

lli check(lli l ,lli r)
{
	lli ans=0;
	lli temp[10][10];
	for(int i=0;i<=7;i++)
	{
		for(int j=0;j<=7;j++)
			temp[i][j]=0;
	}
	
	for(int i=0;i<=n;i++)
	{
		if( (l&lli(pow(2,i)))==0)continue;
		
		for(int j =0;j<=m;j++)
		{
			if(grid[i][j]=='#')temp[i][j]=1;
		}
	}
	
	for(int i=0;i<=m;i++)
	{
		if( (r&lli(pow(2,i)))==0)continue;
		
		for(int j =0;j<=n;j++)
		{
			if(grid[j][i]=='#')temp[j][i]=1;
		}
	}
	
	for(int i=0;i<=7;i++)
	{
		for(int j=0;j<=7;j++)
			if(temp[i][j]==1)ans++;
	}
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lli a,b,c,t,temp1,temp2,x,y,temp,q,d,k,mod=1e9+7;
	cin>>n>>m>>k;
	lli black=0;
	for(int i =0;i<n;i++)
	{
		for(int j =0;j<m;j++)
		{	
			cin>>grid[i][j];
			if(grid[i][j]=='#')black++;
		}
	}
	
	lli ans=0;
	for(int i =0;i<pow(2,n);i++)
	{
		for(int j=0;j<pow(2,m);j++)
		{
			if(black-check(i,j)==k)ans++;	
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef struct {
  char value[5];
  char temp[5];
}Record;


int main(){
  
  int N,i,j,minj,flag,x=0,y=0,a,b;
  scanf("%d",&N);
  Record C[N],A[N],B[N];
  
  for(i=0;i<N;i++){
    scanf("%s",A[i].value);
  }

  for(i=0;i<N;i++){
    strcpy(B[i].value,A[i].value);
    strcpy(C[i].value,A[i].value);
  }



  





  //Bubble sort
  for(i=0;i<=N-1;i++){
    for(j=N-1;j>=i+1;j--){
      if(atoi(A[j].value+1) < atoi(A[j-1].value+1)){
	strcpy(A[j].temp,A[j].value);
	strcpy(A[j].value,A[j-1].value);
	strcpy(A[j-1].value,A[j].temp);
      }
    }
  }

  for(i=0;i<N;i++){
    printf("%s",A[i].value);
    if(i < N -1){
      printf(" ");
    }
  }
  printf("\n");

  for(i=0;i<=N-1;i++){
    for(j=i+1;j<=N-1;j++){
      for(a=0;a<=N-1;a++){
	for(b=a+1;b<=N-1;b++){
	  if(strcmp(C[i].value+1,C[j].value+1)==0  && strcmp(C[i].value,A[b].value)==0 && strcmp(C[j].value,A[a].value)==0){
	    x=1;
	  }
	}
      }
    }
  }
  if(x == 1){
    printf("Not stable\n");
  }else{
    printf("Stable\n");
    }


  
  

  

  //SelectionSort
  for(i=0;i<=N-1;i++){
    minj = i;
    for(j=i;j<=N-1;j++){
      if(atoi(B[j].value+1) < atoi(B[minj].value+1)){
	minj = j;
      }
    }
    strcpy(B[i].temp,B[i].value);
    strcpy(B[i].value,B[minj].value);
    strcpy(B[minj].value,B[i].temp);
  }

  

  for(i=0;i<N;i++){
    printf("%s",B[i].value);
    if(i < N -1){
      printf(" ");
    }
  }

  printf("\n");
  
  for(i=0;i<=N-1;i++){
    for(j=i+1;j<=N-1;j++){
      for(a=0;a<=N-1;a++){
	for(b=a+1;b<=N-1;b++){
	  if(strcmp(C[i].value+1,C[j].value+1)==0 && strcmp(C[i].value,B[b].value)==0 && strcmp(C[j].value,B[a].value)==0){
	    y = 1;
	  }
	}
      }
    }
  }
  if(y == 1){
    printf("Not stable\n");
  }else{
    printf("Stable\n");
    }

  

    return 0;
}
	   



Measured memory_bytes: 2100
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

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

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

struct edge{
    llong to;
    llong cost;
};

vecllong dijkstra(llong start, vector<vector<edge>> edges) {
    vecllong minCost(edges.size(), INF);

    priority_queue<
        pair<llong, llong>,  // cost, index
        vector<pair<llong, llong>>,
        greater<pair<llong, llong>>
    > nodeHeap;

    nodeHeap.push(make_pair(0, start));

    while (!nodeHeap.empty()) {
        llong cost = nodeHeap.top().first;
        llong node = nodeHeap.top().second;
        nodeHeap.pop();

        if (minCost[node] <= cost) {
            continue;
        }

        minCost[node] = cost;

        for_each(edges[node].begin(), edges[node].end(), [&](edge e){
            llong nextNode = e.to;
            llong newCost = cost + e.cost;
            nodeHeap.push(make_pair(newCost, nextNode));
        });
    }

    return minCost;
};

vvecllong minDist;

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

    llong N, M, R;
    cin >> N >> M >> R;

    vecllong visit(R);
    FOR(i, R) {
        llong r;
        cin >> r;
        r--;
        visit[i] = r;
    }

    vector<vector<edge>> edges(N, vector<edge>(0));
    FOR(i, M) {
        llong from, to, dist;
        cin >> from >> to >> dist;
        from--;
        to--;
        edges[from].push_back({to, dist});
        edges[to].push_back({from, dist});
    }

    minDist.resize(N);
    FOR(i, R) {
        minDist[visit[i]] = dijkstra(visit[i], edges);
    }

    llong ans = INF;
    sort(visit.begin(), visit.end());

    do {
        llong cost = 0;
        FOR(i, R - 1) {
            cost += minDist[visit[i]][visit[i + 1]];
        }
        ans = min(ans, cost);
    } while(next_permutation(visit.begin(), visit.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	ll n,ans=0;
	cin>>n;
	vector<ll> a(n);
	for(ll i=0;i<n;i++)
		cin>>a[i];
	for(ll i=1;i<n-1;i++)
	{
		if((a[i]>a[i-1] && a[i]<a[i+1]) or (a[i]<a[i-1] && a[i]>a[i+1]))
			ans++;
	}
	cout<<ans;
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3560
# サイコロを振った回数N
N = int(input())

xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

count = 0

for i in range(N):
    if x[i] == y[i]:
        count += 1
        if count == 3:
            break
    else:
        count = 0
if count >= 3:
    print("Yes")
else :
    print("No")



Measured memory_bytes: 9176
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 131100
#define LL long long
#define INF 40000000000
struct node
{
	LL in,out;
	node(LL _in=0,LL _out=0){in=_in,out=_out;}
};
vector<node>dp[MAXN],tmp1,tmp2;
LL lim;
void vector_merge(vector<node>&G,vector<node>&l,vector<node>&r)
{
	G.clear();
	int s1=l.size(),s2=r.size(),p1=0,p2=0;
	if(s2==0) return;
	while(p1<s1)
	{
		while(p2<s2&&l[p1].out+r[p2].in<=lim) p2++;
		if(p2) p2--;
		if(l[p1].out+r[p2].in<=lim) G.push_back(node(l[p1].in,r[p2].out));
		p1++;
	}
}
void Insert(vector<node>&G,node &x)
{
	int k=G.size();
	if(k==0) G.push_back(x);
	else if(G[k-1].out>x.out) G.push_back(x);
}
void merge_sort(vector<node>&G,vector<node>&l,vector<node>&r)
{
	G.clear();
	int s1=l.size(),s2=r.size(),p1=0,p2=0;
	while(p1!=s1||p2!=s2)
	{
		if(p1==s1) Insert(G,r[p2++]);
		else if(p2==s2) Insert(G,l[p1++]);
		else if(l[p1].in<r[p2].in) Insert(G,l[p1++]);
		else Insert(G,r[p2++]);
	}
}
int d[MAXN],ch[MAXN][2],fa[MAXN],n;
LL dep[MAXN];
void dfs(int u)
{
	if(!d[u])
	{
		dp[u].clear();
		dp[u].push_back(node(dep[u],dep[u]));
		return;
	}
	int ls=ch[u][0],rs=ch[u][1];
	dfs(ls);
	dfs(rs);
	lim+=2*dep[u];
	vector_merge(tmp1,dp[ls],dp[rs]);
	vector_merge(tmp2,dp[rs],dp[ls]);
	merge_sort(dp[u],tmp1,tmp2);
	lim-=2*dep[u];
}
int main()
{
//	freopen("travel.in","r",stdin);
//	freopen("travel.out","w",stdout);
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%d%lld",&fa[i],&dep[i]);
		ch[fa[i]][d[fa[i]]++]=i;
		dep[i]+=dep[fa[i]];
	}
	LL l=0,r=INF,ans;
	while(l<r)
	{
		lim=(l+r)/2;
		dfs(1);
		if(dp[1].size()) r=lim,ans=lim;
		else l=lim+1;
	}
	printf("%lld\n",ans);
}

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

long X[200000];
long L[200000];
long N, M;

int main() {
    cin >> N >> M;
    for (long i = 0; i < M; ++i) cin >> X[i];
    sort(X, X + M);
    for (long i = 0; i < M - 1; ++i) L[i] = X[i+1] - X[i];
    sort(L, L + M - 1, greater<int>());
    int ans = 0;
    if(N >= M){
        ans = 0;
    }else{
        ans = X[M-1] - X[0];
        for(int i = 0; i < N-1; ++i){
            ans -= L[i];
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int num;
  cin >> num;
  
  if(num-((int)(num/10)*10) == 3)
  {
  	cout<<"bon";
  }
  else if(num-((int)(num/10)*10) == 0 ||
         num-((int)(num/10)*10) == 1 ||
         num-((int)(num/10)*10) == 6 ||
         num-((int)(num/10)*10) == 8)
  {
  cout<<"pon";
  }
  else
  {
  cout<<"hon";
  }
}

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

const int maxn=500005;

struct Node
{
	int sum;
	int lson,rson;
}a[maxn*60];
int tot=1;

void buildtree(int id, int l, int r)
{
	if(l==r) return;
	a[id].lson=++tot; a[id].rson=++tot;
	int mid=(l+r)/2;
	buildtree(a[id].lson,l,mid);
	buildtree(a[id].rson,mid+1,r);
}

int change(int id, int l, int r, int x, int dl)
{
//	cout<<"change "<<endl;
	int pos=++tot;
	a[pos]=a[id];
//	cout<<"sum "<<pos<<' '<<a[pos].sum<<endl;
	if(l==r)
	{
		a[pos].sum+=x; 
		return pos;
	}
	int mid=(l+r)/2;
	if(dl<=mid) a[pos].lson=change(a[id].lson,l,mid,x,dl);
	else a[pos].rson=change(a[id].rson,mid+1,r,x,dl);
	a[pos].sum=a[a[pos].lson].sum+a[a[pos].rson].sum;
	return pos;	
}

int query(int id, int l, int r, int dl)
{
//	cout<<"query "<<min_<<' '<<max_<<' '<<l<<' '<<r<<' '<<x<<endl;
	if(l==r) return a[id].sum;
	int mid=(l+r)/2;
	if(dl<=mid) return a[a[id].rson].sum+query(a[id].lson,l,mid,dl);
    return query(a[id].rson,mid+1,r,dl);
}

int n,m;

int d[maxn];

int book[maxn],rk[maxn];

int belong[maxn];

int main()
{
	int maxd;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	buildtree(rk[0],1,n);
	for(int i=1;i<=n;++i)
	{
        if(belong[d[i]])
		{
            int t=change(rk[i-1],1,n,-1,belong[d[i]]);
            rk[i]=change(t,1,n,1,i);
        }
        else
		{
            rk[i]=change(rk[i-1],1,n,1,i);
        }
        belong[d[i]]=i;
    }
	for(int i=1;i<=m;i++)
	{
		int l,r;
		cin>>l>>r;
		cout<<query(rk[r],1,n,l)<<endl;
	}
	return 0;
}

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

ll n,k;

bool f(ll x){
    ll y=0;
    rep(i,min(70ll,n)){
        y+=x;
        x/=2;
    }
    return y<=k;
}

int main(){
    cin>>n;
    vector<ll>t(n+1);
    vector<double>a(n+1);
    a[0]=1.0;
    rep(i,n){
        cin>>t[i+1]>>a[i+1];
        a[i+1]=a[i]*(10.0-a[i+1])/10.0;
    }
    cin>>k;
    ll l,r;
    rep(i,k){
        cin>>l>>r;
        int x=lower_bound(t.begin(),t.end(),l)-1-t.begin(),y=lower_bound(t.begin(),t.end(),r)-1-t.begin();
        printf("%.10f\n",1e9*a[y]/a[x]);
    }
}


Measured memory_bytes: 4408
import java.util.*;

public class Main{
    int h,w,c;
    int max;
    int from,to;
    int ans;
    int[][] panel2;
    int[] dx = {1,-1,0,0};
    int[] dy = {0,0,1,-1};

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

    void solve(){
	Scanner sc = new Scanner(System.in);
	h = sc.nextInt();
	while(h!=0){
	    ans = 0;
	    w = sc.nextInt();
	    c = sc.nextInt();
	    int[][] panel = new int[h][w];
	    for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
		    panel[i][j] = sc.nextInt();
		}
	    }
	    
	    max = Integer.MIN_VALUE;
	    dfs(0,panel);
	    System.out.println(max);

	    h = sc.nextInt();
	}
    }

    //深さ優先探索
    void dfs(int count, int[][] panel){
	if(count==4){
	    if(panel[0][0]==c){return;}
	    from = panel[0][0]; to = c;
	    panel2 = panel;
	    change(0,0);

	    ans = 0;
	    from = c; to = 7;
	    change(0,0);
	    max = Math.max(max,ans);
	    return;
	}

	//パネルのコピー作成
	panel2 = new int[h][w];
	for(int i=0; i<h; i++){
	    for(int j=0; j<w; j++){
		panel2[i][j] = panel[i][j];
	    }
	}
	for(int i=1; i<=6; i++){
	    if(i==panel[0][0])continue;
	    from = panel[0][0]; to = i;
	    change(0,0);
	    dfs(count+1,panel2);
	    for(int k=0; k<h; k++){
		for(int j=0; j<w; j++){
		    panel2[k][j] = panel[k][j];
		}
	    }
	}
    }

    //パネルの色を変える
    void change(int x, int y){
	panel2[y][x] = to;
	ans++;
	for(int k=0; k<4; k++){
	    int nx = x+dx[k];
	    int ny = y+dy[k];
	    if(ny<h && ny>=0 && nx<w && nx>=0 && panel2[ny][nx]==from){
		change(nx,ny);
	    }
	}
    }
}

Measured memory_bytes: 12000
from collections import deque
n,m = map(int, input().split())
t = [[] for i in range(n)]
near = [-1 for i in range(n)]
near[0] = 0
q = deque()
for i in range(m):
    a,b = map(int, input().split())
    t[a-1].append(b-1)
    t[b-1].append(a-1)
for i in range(len(t[0])):
    c = t[0][i]
    near[c] = 0
    q.append(c)
while len(q) > 0:
    e = q.popleft()
    for j in range(len(t[e])):
        c = t[e][j]
        if near[c] == -1:
            near[c] = e
            q.append(c)
print('Yes')
for i in range(1,len(near)):
    print(near[i]+1)


Measured memory_bytes: 34020
#include <bits/stdc++.h>
  
using namespace std;
 
#define endl "\n"
#define JAM(x) cout<< #x <<" = "<<x<<"\n"
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { ll a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
 
 
//Fast Reader
template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPI;
 
const int INF=2e9;
const int MX=100005;
const int MOD=1000000007;
const double PI=acos(-1.0);
 
long long int power(long long int a,long long int b)
{
    a %= MOD;
    long long int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
 
/*_______________________________________________*/


int main()
{
	string s;
    cin>>s;
    int ans=0,temp=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='R')
        temp++;
        else
        {
            ans=max(ans,temp);
            temp=0;
        }
        if(i==2 && s[i]=='R')
        ans=max(ans,temp);
    }
    cout<<ans;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n,h;
    cin >> n >> h;
    int b[100000];
    int a;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp >> b[i];
        a = max(a, tmp);
    }
    sort(b,b+n);
    int cnt = 0;
    int index = n-1 ;
    do{ 
        if(b[index] > a){
            cnt++;
            h -= b[index];
            index--;
        }else{
            break;
        }
    }while(h>0);
    if(h>0){
        cnt += (h-1) / a + 1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
import math
n = input()
prime_count = 0
is_prime = 1

for i in range(0,n):
	is_prime = 1
	prime_check_number = input()
	if prime_check_number == 2:
		prime_count = prime_count + 1
		continue
	elif prime_check_number == 1 or prime_check_number % 2 == 0:
		continue
	else:
		prime_check_number_sqrt = int(math.sqrt(prime_check_number))
		for j in range(3,prime_check_number_sqrt+1,2):
			if prime_check_number % j == 0:
				is_prime = 0
				break

	if is_prime == 1:
		prime_count = prime_count + 1

print(prime_count)


Measured memory_bytes: 5144
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N,M;cin>>N>>M;
    vector<vector<int> >s(M);
    //cout<<"hihihi"<<endl;
    for(int i=0;i<M;i++){
        int k;cin>>k;
        for(int j=0;j<k;j++){
            int a;cin>>a; a--;
            s[i].push_back(a);
        }
    }
    //cout<<"hihihi"<<endl;

    vector<int>p(M);
    for(int i=0;i<M;i++)cin>>p[i];
    //cout<<" hihihihihi"<<endl;

    long long res=0;
    for(int bit=0;bit<(1<<N);bit++){
        bool ok=true;
        for(int i=0;i<M;i++){
            int con=0;
            for(auto v:s[i]){
                if(bit&(1<<v))++con;
            }
            if(con%2!=p[i])ok=false;
        }
        if(ok)res++;
    }
    cout<<res<<endl;
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;

template <class T> using Vec = vector<T>;

/* 定数 */
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

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

#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

bool check(string str, u32 l, u32 r) {
    while(l < r) {
        if (str[l] != str[r]) return false;
        l++; r--;
    }
    return true;
}

void Main() {
    string S;
    cin >> S;
    u32 l, r;
    l = 0; r = S.size() - 1;
    bool a1 = check(S, l, r);
    l = 0; r = (S.size() - 2) / 2;
    bool a2 = check(S, l, r);
    l = (S.size() + 2) / 2; r = S.size() - 1;
    bool a3 = check(S, l, r);
    string result = (a1 && a2 && a3)? "Yes" : "No";
    cout << result << endl;
}


Measured memory_bytes: 256