akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

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

  private FastScanner sc;
  private Scanner scc;

  private void run() {
    sc = new FastScanner();
    scc = new Scanner(System.in);
    int N = scc.nextInt();
    int X = scc.nextInt();

    int next = 0;
    int count = 0;
    for (int i = 0; i < N; i++) {
      int tmp = scc.nextInt();
      next += tmp;
      if (X < next) {
        break;
      }
      count++;
    }

    System.out.println(count + 1);
  }
}


class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

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

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

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
      ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
      throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
      throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}


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

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

    int ans;
    if (S == "RRR") ans = 3;
    else if (S == "SSS") ans = 0;
    else if (S == "RRS" || S == "SRR") ans = 2;
    else ans = 1;
    cout << ans << endl;
    return 0;
}

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

int gcd(int a, int b){
	if(a==0 || b==0) return a==0?b:a;
	int d=0;
	while((a&1)==0 && (b&1)==0){a>>=1; b>>=1; d++;}
	while(1){
		if((a&1)!=0){
			if((b&1)!=0){
				if(a<b) b-=a;
				else if(a>b) a-=b;
				else break;
			}else{
				while((b&1)==0) b>>=1;
			}
		}else{
			while((a&1)==0) a>>=1;
		}
	}
	return a<<d;
}

int main(void){
	int n, i;
	int a[100001];
	int l[100002], r[100002];
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", a+i);
	}
	l[0]=0;
	for(i=1; i<=n; i++){
		l[i] = gcd(l[i-1], a[i]);
	}
	r[n+1]=0;
	for(i=n; i>0; i--){
		r[i] = gcd(r[i+1], a[i]);
	}
	int max=0;
	for(i=1; i<=n; i++){
		int now=gcd(l[i-1], r[i+1]);
		if(now>max) max=now;
	}
	printf("%d\n", max);
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int len[10];
  int v1,v2;
  int i,j;

  while(scanf(" %d",&len[0])!=EOF){
    int lensum=len[0];
    for(i=1;i<10;i++){
      scanf(",%d",&len[i]);
      lensum+=len[i];
    }
    scanf(",%d,%d",&v1,&v2);
    int ratio=v1+v2;
    double place=(lensum*v1*1.0)/ratio; //?????????????????????
    rep(i,10){
      place-=len[i];
      if(place<=0){
	cout<<i+1<<endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 1212
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        mut n: i64
    }

    let mut exps = Vec::new();
    loop {
        exps.push(n.rem_euclid(-2));
        n = n.div_euclid(-2);
        if n == 0 {
            break;
        }
    }
    exps.reverse();
    for exp in exps {
        print!("{}", exp);
    }
}


Measured memory_bytes: 2160
#include<iostream>
#include<vector>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int n;
vector<int> s(50);
vector<int> a(52);

int dfs(int k){
    if(k==n){
        int ret = 24;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int r = abs(s[i] - s[j]);
                ret = min(ret, min(24 - r, r));
            }
        }
        return ret;
    }
    int ret = 0;
    if(a[k]==0||a[k]==12){
        s[k] = a[k];
        ret = max(ret, dfs(k+1));
    }
    else{
        s[k] = a[k];
        ret = max(ret, dfs(k+1));
        s[k] = 24 - a[k];
        ret = max(ret, dfs(k+1));
    }
    return ret;
}

 

int main(){
    cin >> n;
    a[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i+1];
    }
    n++;
    if(n>24){
        puts("0");
        return 0;
    }
    cout << dfs(0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, 1, 1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    int n = inp1;
    vector<int> a = inp(n);

    int q = inp1;

    const int kMax = 100010;
    vector<ll> num(kMax, 0);
    rep(i, n) {
        num[a[i]]++;
    }

    ll sum = 0LL;
    rep(i, kMax) {
        sum += (ll)num[i] * i;
    }

    rep(i, q) {
        int b, c;
        cin >> b >> c;
        num[c] += num[b];
        
        sum -= num[b] * b;
        sum += num[b] * c;

        num[b] = 0;

        Cout(sum);
    }

    return 0;
}


Measured memory_bytes: 4576
N = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
m = a[0]
for ai in a:
    m = lcm(m, ai)

def f(x):
    ret = 0
    for ai in a:
        ret += x%ai
    return ret

print(f(m-1))

Measured memory_bytes: 5332
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<=b;i++)
const int N=1e5+5;
struct node {
	int x, y, id;
	bool operator< ( const node & rhs ) const {
		return y == rhs.y ? x < rhs.x : y < rhs.y;
	}
} a[N];
int n,m,num,now;
int main()
{
	cin>>n>>m;
	rep(i,1,m)
	{
		cin>>a[i].x>>a[i].y;
	}
	sort(a+1,a+1+m);
	rep(i,1,m)
	{
		if(now<a[i].x)num++,now=a[i].y-1;
	}
	cout<<num;

	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
#define pb push_back
#define mp make_pair
#define taskname "A"
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int n , k;
ii a[maxn];
ll res[maxn];
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w  ",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].first;a[i].second = i;
    }
    sort(a + 1 , a + n + 1);
    int pre = n;
    for(int i = n ; i >= 1 ; --i){
        pre = min(pre , a[i].second);
        res[pre] += (a[i].first - a[i - 1].first) * (ll)(n - i + 1);
    }
    for(int i = 1 ; i <= n ; ++i)cout << res[i] << '\n';
}

Measured memory_bytes: 2688
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    if (a<b){
        printf("a < b\n");
    }
    else if (a>b){
        printf("a > b\n");
    }
    else {
        printf("a == b\n");
    }
    return 0;
}

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

a = [int(i) for i in a]

diff = list()
diff.insert(0,K-a[N-1]+a[0]) # seq 1
for i in range(2,N+1):       # seq 2 to N-1
  diff.insert(i-1,abs(a[i-1]-a[i-2]))

# print (diff)

print (sum(diff)-max(diff))

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

using namespace std;

long long n,ans = 0;
long long a[200005],b[200005];

int main(){
	cin >> n;
	for(int i = 1;i <= n;i ++)
		cin >> a[i], b[i] = a[i];
	sort(b + 1,b + 1 + n);
	for(int i = 1; i <= n; ++i) 
		a[i] = lower_bound(b + 1,b + 1 + n,a[i]) - b;
	for(int i = 1; i <= n; ++i) 
		if((a[i] & 1) ^ (i & 1)) ans++;
	cout << (ans >> 1) << endl;
	return 0;
}

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

int N, t[1 << 18], col[1 << 18], cnts, deg[1 << 18]; long double p[1 << 18];
vector<int>X[1 << 18], Y[1 << 18], G[1 << 18], V; bool used[1 << 18];

void init() {
	for (int i = 0; i < (1 << 18); i++) {
		t[i] = 0; col[i] = 0; deg[i] = 0; p[i] = 0; X[i].clear(); Y[i].clear(); G[i].clear(); used[i] = false;
	}
	V.clear(); cnts = 0;
}

void dfs(int pos) {
	used[pos] = true;
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i]] == true) continue;
		dfs(X[pos][i]);
	}
	V.push_back(pos);
}

void dfs2(int pos) {
	col[pos] = cnts; G[cnts].push_back(pos);
	for (int i = 0; i < Y[pos].size(); i++) {
		if (col[Y[pos][i]] >= 1) continue;
		dfs2(Y[pos][i]);
	}
}

int main() {
	while (true) {
		cin >> N; if (N == 0) break;
		init();
		for (int i = 1; i <= N; i++) {
			cin >> p[i] >> t[i]; p[i] = 1.0L - p[i];
			for (int j = 1; j <= t[i]; j++) { int a; cin >> a; X[i].push_back(a); Y[a].push_back(i); }
		}
		for (int i = 1; i <= N; i++) {
			if (used[i] == true) continue;
			dfs(i);
		}
		reverse(V.begin(), V.end());
		for (int i = 0; i < V.size(); i++) {
			if (col[V[i]] >= 1) continue;
			cnts++; dfs2(V[i]);
		}

		for (int i = 1; i <= N; i++) {
			for (int j = 0; j < X[i].size(); j++) {
				if (col[i] != col[X[i][j]]) deg[col[X[i][j]]]++;
			}
		}
		long double E = 1;
		for (int i = 1; i <= cnts; i++) {
			if (deg[i] >= 1) continue;
			long double F = 1;
			for (int j = 0; j < G[i].size(); j++) F *= (1.0L - p[G[i][j]]);
			E *= (1.0L - F);
		}
		printf("%.12Lf\n", E);
	}
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll N, W; cin >> N >> W;
	vector<ll> w(N), v(N);
	for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
	for(int i = 0; i <= N; i++) for(int j = 0; j <= W; j++) dp[i][j] = -INF;
	for(int i = 0; i <= N; i++) dp[i][0] = 0;
	for(int i = 0; i <= W; i++) dp[0][i] = 0;
	for(int s = 1; s <= N; s++) for(int t = 1; t <= W; t++) {
		dp[s][t] = dp[s - 1][t];
		if(t - w[s - 1] >= 0) dp[s][t] = max(dp[s][t], dp[s - 1][t - w[s - 1]] + v[s - 1]);
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 83232
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String x="";
    for(int i=0;i<s.length();i++)
    {
      x+="x";
    }
    System.out.println(x);
  }
}

Measured memory_bytes: 23892
n = int(input())
list1 = list(map(int,input().split()))
cout = 0 #最終的な水やり回数
now_water = 0 #現在水やりをしている高さ-1(これは常に最高値を持つ)
i = 0
def func(flower):
	global cout
	global i
	if flower == n-1: #一番右側の花の処理
		if list1[flower] <= now_water:
			cout += 1
			i = flower + 1
			return
		else:
			cout += 1
			i = flower + 1
			return

	elif list1[flower] <= now_water: #終了条件
		cout += 1 #一連の水やり操作の終了
		i = flower + 1
		return
	else:
		func(flower + 1)

while now_water <= max(list1): #花の高さがlist内の最大値になるまで
	i = 0
	while i < n: #now_waterに対して一巡させる
		if list1[i] > now_water:
			func(i)
		else:
			i+=1
	now_water += 1





print(cout)

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
      fastio;
     int a,b;
     cin>>a>>b;
     if(a>b)
     swap(a,b);
     for(int i=1;i<=3;i++)
     {
      if(i!=a&&i!=b)
        cout<<i<<endl;
     } 
    }

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
char s[1001];
int main()
{
    cin>>s;
    int l=strlen(s);
    for(int i=0;i<l;i++)
    {
        if(s[i]=='C'){
        for(int j=i+1;j<l;j++)
            if(s[j]=='F') 
            {
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> V(N);
    vector<int> C(N);

    int ans = 0;

    REP(i,N){
        cin >> V[i];
    }
    REP(i,N){
        cin >> C[i];
    }
    REP(i,N){
        ans += max(V[i]-C[i],  0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int sum=0;
        	String x=sc.next();
            int n=x.length();
            int[] num = new int[n];
        	if(x.equals("0"))
                break;
            
            String[] str = x.split("");
            for(int i=0;i<n;i++){
                sum+=Integer.parseInt(str[i]);
            }
            System.out.println(sum);
        }       
    }
}



Measured memory_bytes: 26984
#include <stdio.h>

int main(void){
    double hi,lo, tmp;

    hi = 0;
    lo = 65536;
    while (scanf("%lf", &tmp)!= EOF){
        if (tmp > hi) hi = tmp;
        if (tmp < lo) lo = tmp;
    }
    printf("%f\n", hi-lo);

    return 0;
}

Measured memory_bytes: 1076
/*
   ~~~~~~~~~~~~~~~~~~~
   \  |\/| | |\ | |  /
   /  |  | | |/ |_|  \
   ~~~~~~~~~~~~~~~~~~~
*/
#include<iostream>
#define ll long long
using namespace std;
int main()
{	
	char s[25];
	ll i;
	cin>>s;
	for(i=0;i<3;i++){
		cout<<s[i];
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 3596
d, n = map(int, input().split())

if d == 0:
    if n <= 99:
        print(n)
    else:
        print(101)
elif d == 1:
    if n <= 99:
        print(100 * n)
    else:
        print(10100)
else:
    if n <= 99:
        print(10000 * n)
    else:
        print(1010000)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if( ( a>= 1 && a <=9 ) && (b >=1 && b <= 9)){
    cout << a *b << endl;
  }else{
    cout << -1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] c = new int[m+1];
        for (int i = 1; i <= m; i++) {
            c[i] = sc.nextInt();
        }
        int[][] dp = new int[m+1][n+1];
        for (int i = 0; i < m+1; i++) {
            Arrays.fill(dp[i], n);
        }
        dp[0][0] = 0;
        for (int i = 1; i <= m; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j] = dp[i-1][j];
                if(j < c[i])continue;
                if(dp[i][j] > dp[i-1][j-c[i]] + 1) dp[i][j] = dp[i-1][j-c[i]] + 1;
                if(dp[i][j] > dp[i][j-c[i]] + 1) dp[i][j] = dp[i][j-c[i]] + 1;
            }
        }
        System.out.println(dp[m][n]);
        sc.close();

    }

}



Measured memory_bytes: 31120
#include<iostream>
#include<vector>

using namespace std;

const int mx= 1e5+123;
int vis[mx];
vector<int> adj[mx];

void dfs ( int u)
{
    vis[u]=1;

    for(auto v: adj[u])
    {
        if (vis[v]== 0)
            dfs(v);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int n, m;

    cin>> n>> m;

    for(int i=1; i<=m; i++)
    {
        int u, v;
        cin>> u>>v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int cnt=0;

    for( int i=1; i<=n; i++)
    {
        if( vis [i]==0)
        {
            dfs(i);
            cnt++;
        }
    }
    cout<< cnt- 1<< endl;

    return 0;
}





Measured memory_bytes: 10000
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  if(n<28){
    while(n>=0){
      if(n%4==0){
        cout << "Yes" << endl;
        return 0;
      }
      n-=7;
    }
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

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

int main() {
  int A, B, N;
  cin >> A >> B;
  N = B - A + 1; 
  int count = 0;
    
  for (int i = 0; i < N; i++) {
    int p, q, r, s;
    p = A % 10;
    q = (A / 10) % 10;
    r = (A / 1000) % 10;
    s = A / 10000;
    
    if (p == s && q == r){
      count += 1;
    }
    A += 1;
  }
  cout << count << endl;
}

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

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

    int n,m;cin>>n>>m;
    vector<vector<int>> v(m);
    for(int i=0;i<m;i++)
    {
        int k;cin>>k;
        for(int j=0;j<k;j++)
        {
            int s;cin>>s;
            v[i].push_back(s-1);
        }
    }

    vector<int> p(m);
    for(int i=0;i<m;i++)cin>>p[i];

    int ans=0;

    int sz=pow(2,n);
    for(int i=0;i<sz;i++)
    {
        bool ok=true;
        for(int j=0;j<m;j++)
        {
            int cnt=0;
            for(auto s:v[j])
            {
                if(i&1<<s)cnt++;
            }
            if(cnt%2!=p[j])ok=false;
        }
        if(ok)ans++;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 4084
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
        public static void main(String[] args){
          long A = getLong();
          long B = getLong();
          long C = getLong();
          long K = getLong();
          if(K % 2 == 0){
            myout(A - B);
          }else{
            myout(B - A);
          }
        }
        //便利メソッド追加枠ここから

        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 21716
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    b=[]
    for i in range(n)[::-1]:
        for e in b:
            a[i]=min(a[i],a[i]^e)
        if a[i]:
            if s[i]=="0":
                b+=[a[i]]
            else:
                print(1)
                break
    else:
        print(0)

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

const int MAXN = 5e5+5;
const int MOD = 1e9+7;
long long Fact[MAXN] = {1};
long long Cn[MAXN];

inline long long fpow(long long a, long long b)
{
    long long res = 1;
    a %= MOD;
    while(b)
    {
        if(b & 1)
            (res *= a) %= MOD;
        (a *= a) %= MOD;
        b >>= 1;
    }
    return res;
}

inline long long A(long long m, long long n)
{
    return (Fact[m] * fpow(Fact[m - n], MOD - 2)) % MOD;
}

int main()
{
    long long N, M;
    scanf("%lld %lld", &N, &M);

    for(int i = 1; i <= M; ++i)
        Fact[i] = (Fact[i-1] * i) % MOD;

    Cn[0] = 1;
    for(int i = 1; i <= N; ++i)
    {
        Cn[i] = (((Cn[i-1] * (N - i + 1)) % MOD) * fpow(i, MOD - 2)) % MOD;
    }

    long long ans = 0;

    int flag = 1;
    for(int i = 0; i <= N; i++, flag = - flag)
        ans = (ans + flag * ((Cn[i] * A(M - i, N - i)) % MOD) + MOD) % MOD;

    cout << (ans * A(M, N)) % MOD << endl;



    return 0;
}
/*
4 6 7 5
*/


Measured memory_bytes: 11340
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Sarray();
            var ans = 0L;
            for (var i = 0; i < N; ++i)
            {
                ans = (ans + (Ai.Count(a => Ai[i] > a) * ((K - 1) * K / 2 % Mod)) % Mod) % Mod;
                ans = (ans + Ai.Skip(i).Count(a => Ai[i] > a) * K % Mod) % Mod;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

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

struct Proc{
    string nam;
    int tim;
};

Proc Q[100001];

class Queue{
    private:
        int fp;
        int rp;
    public:
        Queue(){fp=0; rp=0;}
        int next(int p)const{return (p+1)%100001; }
        bool isEmpty() const {return (rp==fp); }
        void push(Proc d);
        Proc pop();
};
void Queue::push(Proc d){
    Q[rp]=d;
    rp=next(rp);
}

Proc Queue::pop(){
    Proc tmp;
    tmp.nam=Q[fp].nam;
    tmp.tim=Q[fp].tim;
    fp=next(fp);
    return tmp;
}

int main(){
    Queue que;
    int n,q;
    cin>>n>>q;

    for(int i=0;i<n;i++){
        Proc p;
        cin>>p.nam>>p.tim;
        que.push(p);
    }
    int total=0;
    while(!que.isEmpty()){
        Proc p=que.pop();
        if(p.tim<=q){
            total+=p.tim;
            cout<<p.nam<<' '<<total<<endl;
        }else{
            total+=q;
            p.tim-=q;
            que.push(p);
        }
    }
    return 0;
}


Measured memory_bytes: 6960
#include<stdio.h>
int main(void)
{
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/b;
    printf("%d %d %lf\n",d,r,f);
  return 0;
}

Measured memory_bytes: 2632
#include <iostream>
#include <queue>
#include <utility>

#define X second
#define Y first

using namespace std;

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

int main(){
    int n; cin >> n;
    int cnt = 0;
    while (n--) {
        cnt++;
        int map[8][8] = {0};
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                char tmp; cin >> tmp;
                if (tmp == '0')
                    map[i][j] = 0;
                else
                    map[i][j] = 1;
            }
        }

        queue<pair<int, int> > bomb;
        int x, y; cin >> x >> y;
        bomb.push(make_pair(x-1, y-1));

        while (!bomb.empty()) {
            pair<int, int> l = bomb.front();
            if (map[l.X][l.Y] == 0) {
                bomb.pop();
                continue;
            } else {
                map[l.X][l.Y] = 0;
            }
            for (int i = 0; i < 4; i++) {
                for (int j = 1; j < 4; j++) {
                    x = l.X + (dx[i] * j);
                    y = l.Y + (dy[i] * j);
                    if (0>x || 8<=x || 0>y || 8<=y) {
                        continue;
                    }
                    if (map[x][y]) {
                        if (j != 0) {
                            bomb.push(make_pair(y, x));
                        }
                    } else {
                        continue;
                    }
                }
            }
            bomb.pop();
        }

        cout << "Data " << cnt << ":" << endl;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                cout << map[i][j];
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Set;
import java.util.HashMap;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            HashMap<String, Integer> map = new HashMap<>();
            int n = in.nextInt();

            for (int i = 0; i < n; ++i) {
                String s = in.next();
                if (isOk(s)) {
                    map.put(s.charAt(0) + "", map.getOrDefault(s.charAt(0) + "", 0) + 1);
                }
            }

            if (map.keySet().size() < 3) {
                out.println(0);
            } else {
                int[] arr = new int[map.keySet().size()];
                int i = 0;
                for (String s : map.keySet()) {
                    arr[i++] = map.get(s);
                }

                long ans = 0;
                for (i = 0; i < arr.length; ++i) {
                    for (int j = i + 1; j < arr.length; ++j) {
                        for (int k = j + 1; k < arr.length; ++k) {
                            ans += (long) arr[i] * (long) arr[j] * (long) arr[k];
                        }
                    }
                }

                out.println(ans);
            }
        }

        private boolean isOk(String s) {
            char c = s.charAt(0);

            return c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H';
        }

    }
}



Measured memory_bytes: 46648
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; cin >> n; std::vector<i64> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(begin(a), end(a));
	
	i64 ans = a.back() - a[0];
	int A = 0, B = n - 1;
	while(A < B) {
		if(n - A - 2 == n - B) {
			ans += std::max(std::abs(a[A] - a[n - A - 2]), std::abs(a[B] - a[n - B]));
		} else {
			ans += std::abs(a[A] - a[n - A - 2]);
			ans += std::abs(a[B] - a[n - B]);
		}
		i64 tmp = n - B;
		B = n - A - 2;
		A = tmp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
N, MAX_W = map(int, input().split())  # N: 品物数, MAX_W: ナップサックの容量
items = [list(map(int, input().split())) for _ in range(N)]  # items[i]: i番目の品物の（価値, 重さ）


# dp[i][j] := i番目の品物までみた時に、重さの総和がj以下であるように品物を入れた場合の価値の総和の最大値
# 0番目、重さ0も考慮しているのが少しポイント！
dp = [[0] * (MAX_W + 1) for _ in range(N + 1)]

# ここからdpテーブルを順に埋めていく
for i, (v, w) in enumerate(items):
    for j in range(MAX_W + 1):  # Pythonは + 1 しないと MAX_W番目まで計算しないため
        # 次の品物を入れない場合
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

        # 次の品物を入れてもナップサックの容量を超えないか判定
        if j + w <= MAX_W:
            # 次の品物を入れる場合
            dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)


# N番目の品物までみた時に、重さの総和がナップサックの容量以下であるように品物を入れた場合の価値の総和の最大値 が答え！
print(dp[N][MAX_W])



Measured memory_bytes: 41892
import Control.Monad(replicateM)
import Data.List(sort)
main = do
    [n,x] <- map read . words <$> getLine
    d <- replicateM n readLn :: IO [Int]
    let f a ac = if sum(ac) >= x then ac else a:ac
    let fn = foldr f [] d
    print $ ((x - sum fn) `div` minimum d) + length fn

Measured memory_bytes: 1020
N=int(input())
S=list(map(int,input().split()))

counter=0
for i in range(0,N-1):
    min_,min_index=min(S[i:]),S[i:].index(min(S[i:]))+i
    first_element,first_element_index=S[i],i
    
    if min_index!=first_element_index:
        counter+=1
        S[first_element_index],S[min_index]=S[min_index],S[first_element_index]
        
print(*S)
print(counter)


Measured memory_bytes: 5608
N,M = map(int, input().split())

goodObservatory = [1]*N

H = list(map(int, input().split()))

for i in range(M):
	A,B = map(int, input().split())
	if H[A-1] > H[B-1]:
		goodObservatory[B-1] = 0
	elif H[A-1] < H[B-1]:
		goodObservatory[A-1] = 0
	elif H[A-1] == H[B-1]:
		goodObservatory[A-1] = 0
		goodObservatory[B-1] = 0

print(sum(goodObservatory))

Measured memory_bytes: 20816
# -*- coding: utf-8 -*-

N = int(raw_input())
A = map(int, raw_input().split())
flag = 1
count = 0
while flag:
    flag = 0
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A[j-1], A[j] = A[j], A[j-1]
            count += 1
            flag = 1
print " ".join(map(str, A))
print count

Measured memory_bytes: 6452
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = []
cou = 0
anti = 0
for i in range(n):
    a = A[i]
    b = B[i]
    if (a - b) < 0:
        cou += 1
        anti += (a-b)
    else:
        D.append(a-b)
if anti == 0:
    ans = 0
elif sum(D) + anti < 0:
    ans = -1
else:
    D.sort(reverse = True)
    l = len(D)
    for i in range(l):
        anti += D[i]
        if anti >= 0:
            ans = cou + i + 1
            break
print(ans)
    

Measured memory_bytes: 19124
#include<bits/stdc++.h>
using namespace std;
#define FF 99999
int main(){
        int h,w;
        cin>>h>>w;
        vector<string> m(h);
        int sum=0;
        for(int i=0; i<h; i++){
                cin>>m[i];
                for(int j=0; j<w; j++){
                        if(m[i][j]=='.')
                                sum++;
                }
        }
        sum-=1;
        vector<vector<int>> route(h,vector<int>(w,FF));
        route[0][0]=0;
        pair<int,int> ax;
        ax.first=0,ax.second=0;
        queue<pair<int,int>> now;
        now.push(ax);

        while(!now.empty()){
                ax=now.front();now.pop();
                int tx=ax.first,ty=ax.second;
                if(tx==w-1&&ty==h-1){
                        cout<<sum-route[h-1][w-1];
                        return 0;
                }
                int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
                for(int i=0; i<4; i++){
                        int ttx=tx+dx[i],tty=ty+dy[i];
                        if(ttx<0||ttx>=w||tty<0||tty>=h)
                                continue;
                        if(m[tty][ttx]=='.'&&route[tty][ttx]==FF){
                                route[tty][ttx]=route[ty][tx]+1;
                                now.push(pair<int,int>(ttx,tty));
                        }
                }
        }
        cout<<-1;
}

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

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

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

    sort(vec.rbegin(), vec.rend());
    stack<double> sta;
    for (int i = 0; i < n; i++) {
        sta.push(vec[i]);
    }
    
    while (sta.size() > 1) {
        double a = sta.top();
        sta.pop();
        double b = sta.top();
        sta.pop();
        double c = (double) (a + b) / 2;
        sta.push(c);
    }
    double res = sta.top(); 

    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

struct node{
	int a,b,c,d;
}Q[55];
int n,m,q;
int s[15],ans;

void check()
{
	int num=0;
	for(int i=0;i<q;i++){
		if(s[Q[i].b]-s[Q[i].a]==Q[i].c) num+=Q[i].d;
	}
	ans = max(ans,num);
}

void dfs(int pos,int val)
{
	s[pos] = val;
	if(pos==n) {
		check();return ;
	}
	for(int i=val;i<=m;i++){
		dfs(pos+1,i);
	}
}

int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		Q[i] = (node){a,b,c,d};
	}
	dfs(1,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
int main()
{
	string s;
	cin >> s;
	int nextL=0,lastR=0;
    vector<int> ans(s.size());
	rep(i,s.size()){
		while(s[nextL] != 'L' || nextL < i){
			nextL++;
		}
		if(s[i] == 'R'){
			lastR = i;
			if((nextL-i)%2 == 0){
				ans[nextL]++;
			}else{
				ans[nextL-1]++;
			}
		}else{
			if((i-lastR)%2 == 0){
				ans[lastR]++;
			}else{
				ans[lastR+1]++;
			}
		}
	}
	rep(i,s.size()){
		cout << ans[i] << ' ';
	}
	return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<i32>();

    let mut ans = 0;

    for i in 1..n+1 {
        let mut j = i;
        let mut cnt = 0;
        while j > 0 {
            cnt += 1;
            j /= 10;
        }

        if cnt%2 == 1 {
            ans += 1;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define repr(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n)
    {
        rep(i, n) par[i] = i;
    }

    int root(int x)
    {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

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

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

    int n, m; cin >> n >> m;
    UnionFind uf(n);
    int* a = new int[n];
    rep(i, n)
    {
        int t; cin >> t;
        a[i] = t - 1;
    }
    rep(i, m)
    {
        int x, y; cin >> x >> y;
        uf.unite(a[x - 1], a[y - 1]);
    }
    int s = 0;
    rep(i, n)
    {
        s += uf.same(a[i], i);
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int i,j,c,k;
	c=0;
	k=0;
	for(i=1 ; i<=3 ; i++)
	{
	scanf("%d",&j);
	if(j==5) c++;
	if(j==7) k++;
	}
	if(c==2 && k==1) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
n = int(raw_input())
m = map(int, raw_input().split())
a = [1 for i in xrange(n)]
ans = 0
for i in xrange(n):
  if i > 0 and m[i] <= m[i-1]:
    a[i] += a[i-1]
  ans = max(ans, a[i])
print ans-1


Measured memory_bytes: 11316
#include <stdio.h>
#include <stdbool.h>

#define MAX 1000000

int main(void)
{
    int i, j;

    bool isPrime[MAX];
    isPrime[0] = isPrime[1] = false;
    for (i = 2; i < MAX; i++) {
        isPrime[i] = true;
    }

    int n, n_max = 1;
    int cnt;
    while (scanf("%d", &n) != EOF) {
        if (n > n_max) {
            for (i = n_max + 1; i <= n; i++) {
                if (isPrime[i] == true) {
                    for (j = i + i; j <= MAX; j += i) {
                        isPrime[j] = false;
                    }
                }
            }
            n_max = n;
        }
        cnt = 0;
        for (i = 2; i <= n; i++) {
            if (isPrime[i] == true) {
                cnt++;
            }
        }
        printf("%d\n", cnt);

    }

    return 0;
}

Measured memory_bytes: 1572
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
#define minn(x,y) x=min(x,y)
#define maxx(x,y) x=max(x,y)
using namespace std;
map<ll,int> ma;
ll mod=189457896545678ll;
int a[30];
ll hsh(string s)
{
	int i;
	memset(a,0,sizeof(a));
	for(i=0;i<10;i++)
	{
		a[s[i]-'a']++;
	}
	ll h=0;
	for(i=0;i<26;i++)
	{
		h=(h*11+a[i])%mod;
	}
	return h;
}
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d",&n);
	string s;
	for(i=0;i<n;i++)
	{
		cin>>s;
		ll h=hsh(s);
		ma[h]++;
	}
	map<ll,int>::iterator it;
	ll ans=0;
	for(it=ma.begin();it!=ma.end();it++)
	{
		x=(*it).se;
		ans+=1ll*x*(x-1)/2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 6528
#include<stdio.h>

int main(){

int n,r;
while(1){
scanf("%d%d",&n,&r);if(n==0&&r==0)break;
int N[52]={};int N2[52]={};
for(int i=1;i<=n;i++){
N[i]=1+n-i;N2[i]=1+n-i;}



for(int i=0;i<r;i++)
{int p,c;
scanf("%d%d",&p,&c);
for(int j=1;j<p;j++){
N2[j+c]=N[j];
}

for(int j=p;j<p+c;j++){
N2[j-p+1]=N[j];
}
for(int j=0;j<=n;j++)
N[j]=N2[j];

}
printf("%d\n",N2[1]);
}
return 0;
}

Measured memory_bytes: 1028
import qualified Data.ByteString.Char8 as C

main = C.interact $ put . sol . get

get = tail . C.words

put = C.pack . show

sol [s1,s2] = g 1 . f [] $ C.zipWith (\a b -> if a==b then 1 else 2) s1 s2

f s []        = s
f s [a]       = a:s
f s (2:2:as)  = f (2:s) as
f s (2:1:as)  = error "whoa!"
f s (1:a:as)  = f (1:s) (a:as)

g t []        = t
g t [1]       = t .*. 3
g t [2]       = t .*. 6
g t [2,2]     = t .*. 18
g t [a,a']    = t .*. 6
g t (1:2:as)  = g t         (2:as)
g t (2:2:as)  = g (t .*. 3) (2:as)
g t (a:a':as) = g (t .*. 2) (a':as)

(.*.) = ((`mod` p) .) . (*)

p = 10^9+7 :: Int

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    vector<int> a(MAX,0);
    rep(i,MAX){
        if(i%2==0) continue;
        if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    vector<int> s(MAX+1,0);
    rep(i,MAX) s[i+1] = s[i] + a[i];

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
using namespace std;
int main()
{
	int H, W;
	cin >> H >> W;
	vector<vector<string>> C( H, vector<string>( W ) );
	REP( i, H ){
		REP( j, W ){
			cin >> C[i][j];
		}
	}
	REP( i, H ){
		REP( j, W ){
			cout << C[i][j]<< endl;
			cout << C[i][j]<< endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
int main(void) {
	double x1, x2, y1, y2, a;
	scanf("%lf %lf %lf %lf", &x1, &x2, &y1, &y2);
	a = sqrt((y1 - x1) * (y1 - x1) + (y2 - x2) * (y2 - x2));
	printf("%f\n", a);
	return 0;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ====================================================================

int main() {
  int h, w;
  cin >> h >> w;
  string grid[h];
  for (int i = 0; i < h; i++) cin >> grid[i];

  ll dp[h][w];
  dp[0][0] = 1;

  // 初期化
  for (int x = 1; x < w; x++)
    dp[0][x] = (grid[0][x] == '#' ? 0 : dp[0][x - 1]);
  for (int y = 1; y < h; y++)
    dp[y][0] = (grid[y][0] == '#' ? 0 : dp[y - 1][0]);

  // DPする
  for (int y = 1; y < h; y++) {
    for (int x = 1; x < w; x++) {
      if (grid[y][x] == '#')
        dp[y][x] = 0;  // 壁に行く方法は0通りなので(?)
      else {
        dp[y][x] = (dp[y - 1][x] + dp[y][x - 1]) % MOD;
      }
    }
  }

  // // 確認用
  // for (int i = 0; i < h; i++) {
  //   for (int j = 0; j < w; j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  string a, b;
  cin >> a >> b;
  if (a.size() != b.size()) {
    if (a.size() > b.size()) cout << "GREATER" << endl;
    else cout << "LESS" << endl;
    return;
  }
  if (a > b) cout << "GREATER" << endl;
  else if (a < b) cout << "LESS" << endl;
  else cout << "EQUAL" << endl;
}

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

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
using namespace std;

vector<ll> a;

ll cul(int x,int y){
	if(y==0)
		return a[x];
	else if(y==1)
		return (a[x]!=0?a[x] % 2:2);
	else if(y==2)
		return (a[x] % 2)^1;
	else if(y==3)
		return (a[x]!=0?a[x] % 2:2);
	else if(y==4)
		return a[x];
}

void solve()
{
	int l;
	cin>>l;
	a.resize(l);
	rep(i, l) cin >> a[i];
	vector<vector<ll>> dp(l + 5, vector<ll>(5,INF));
	rep(i,5)dp[0][i] = 0;
	rep(i, l)
	{
		rep(j,5){
			REP(k,j,5){
				chmin(dp[i + 1][k], dp[i][j] + cul(i,j));
			}
		}
	}
	ll ans = dp[l][4];
	//rep(i, 5) chmin(ans, dp[l][i]);
	cout << ans;
}

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


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		String[] ranking = sc.next().split("");
		int success = 0;
		int rank_foreign = 1;
		for (String s : ranking) {
			switch (s) {
			case "c":
				System.out.println("No");
				break;
			case "a":
				if (success < a + b) {
					System.out.println("Yes");
					success++;
				} else {
					System.out.println("No");
				}
				break;
			case "b":
				if (success < a + b && rank_foreign <= b) {
					System.out.println("Yes");
					success++;
					rank_foreign++;
				} else {
					System.out.println("No");
				}
				break;
			}
		}

	}

}


Measured memory_bytes: 46044
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String[] info = sc.nextLine().split(" ");
		Queue<Process> entries = new LinkedList<>();
		int size = Integer.parseInt(info[0]);
		int runtime = Integer.parseInt(info[1]);
		for(int i = 0; i < size; i++) {
			info = sc.nextLine().split(" ");
			entries.add(new Process(info[0], Integer.parseInt(info[1])));
		}
		sc.close();
		int totalTime = 0;
		while(entries.size() > 0) {
			Process temp = entries.remove();
			if(temp.getTime() > runtime) {
				totalTime += runtime;
				temp.setTime(temp.getTime() - runtime);
				entries.add(temp);
			}
			else {
				totalTime += temp.getTime();
				System.out.println(temp.getName() + " " + totalTime);
			}
		}
	}
}

class Process{
	String name;
	int time;
	
	public Process(String n, int t) {
		this.name = n;
		this.time = t;
	}
	
	public int getTime() {
		return this.time; 
	}
	
	public void setTime(int t) {
		this.time = t;
	}
	
	public String getName() {
		return this.name;
	}
}



Measured memory_bytes: 108336
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[])
{
	LL N, a[100000], sum = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	LL x = (N * (N + 1)) / 2, y = sum / x;
	bool ans = (sum % x) == 0;
	if (ans) {
		int m;
		for (int i = 0; i < N; ++i) {
			if (a[i] < y || a[i] > N * y) {
				ans = false;
			}
			LL b = a[i] + (N - i) * y;
			if (i > 0 && m != (b % N)) {
				ans = false;
				break;
			} else {
				m = b % N;
			}
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 1024