akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>


using namespace std;

int ok(int64_t X) {

	for (int64_t i = 2; i < X; i++) {
		if (X%i == 0) {
			return 0;
		}

	}
	return 1;
}

int main() {


	int64_t X;
	cin >> X;

	while (!ok(X)) {
		X++;
	}

	cout << X;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000

int main(){
  int a[N];
  int change, n, x, i, j;

  scanf("%d", &n);
  for(j = 0; j < n; j++) scanf("%d", &a[j]);

  x = a[n - 1];
  i = -1;

  for(j = 0; j < n - 1; j++){
    if(a[j] <= x){
      i++;
      change = a[i];
      a[i] = a[j];
      a[j] = change;
    }
  }
  change = a[i + 1];
  a[i + 1] = a[n - 1];
  a[n - 1] = change;

  for(j = 0; j < n - 1; j++){
    if(j == i + 1) printf("[%d] ", a[j]);
    else printf("%d ", a[j]);
  }
  printf("%d\n", a[n - 1]);

  return 0;
}

Measured memory_bytes: 992
n,m,c = (int(i) for i in input().split())
b = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
cnt = 0
for i in range(n):
  if sum(a[i][j] * b[j] for j in range(m)) + c > 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	int a,b,x;
	char op;
	while(op!='?'){
		scanf("%d %c %d",&a,&op,&b);
	
		if(op=='+'){
			x=a+b;
		}else if(op=='-'){
			x=a-b;
		}else if(op=='*'){
			x=a*b;
		}else if(op=='/'){
			x=a/b;
		}else {
			break;
		}
		printf("%d\n",x);
		
	}
	return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int N, endbit, Mask;
int dp[1 << 16][16];

int rec(int bit, int ptr){
  if(bit == endbit) return 0;
  if(~dp[bit][ptr]) return dp[bit][ptr];
  int ret = INF;
  for(int i = 0; i < N; i++){
    if((bit ^ endbit) & (1 << i)){
      for(int j = i + 1; j < N; j++){
        if((bit ^ endbit) & (1 << j) && ((bit >> i) ^ (bit >> j)) & 1){
          int nextbit = bit ^ (1 << i) ^ (1 << j);
          int cost = abs(ptr - i) + j - i;
          ret = min( ret, rec( nextbit, j) + cost);
          cost = abs(ptr - j) + j - i;
          ret = min( ret, rec( nextbit, i) + cost);
        }
      }
    }
  }
  return dp[bit][ptr] = ret;
}

int main(){
  int bit;
  string A, B;

  while(cin >> N, N){
    cin >> A >> B;

    Mask = (1 << N) - 1;
    bit = 0, endbit = 0;
    for(int i = 0; i < A.length(); i++){
      bit |= (A[i] == 'W') << i;
      endbit |= (B[i] == 'W') << i;
    }

    fill_n( *dp, (1 << 16) * 16, -1);
    int ret = INF;
    for(int i = 0; i < A.length(); i++){
      ret = min( ret, rec(bit, i));
    }
    cout << ret << endl;
  }
}

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

template <typename T>
inline T read(){
    T x=0,f=1;char c=getchar();
    while(!isdigit(c)){ if(c=='-') f=-f;c=getchar();}
    while(isdigit(c)){x=(x<<3)+(x<<1)+(c-48);c=getchar();}
    return x*f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf=1e9+1e7;

lint n,m;

int main(void){

    // freopen("testdata.in","r",stdin);
    // freopen("testdata.out","w",stdout);

    scanf("%lld%lld",&n,&m);
    if(abs(n-m)<=1) puts("Brown");
    else puts("Alice");

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();

    ll ans = 0;
    for (int msk = 0; msk < (1 << (len-1)); msk++) {
        ll num = S[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (msk & 1 << i) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << endl;

    return 0;
}

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

const int MAX_KEY_LENGTH = 12;
const int N_KEY_CHARS = 4;

class Dict {
    int *KEYS;
    int char_to_id(char);
    int to_hash(char*);
    public:
        Dict();
        void insert(char*);
        bool has(char*);
};

Dict::Dict() {
    int max_hash = 0, w = 1;
    for (int i = 0; i < MAX_KEY_LENGTH; i++, w *= N_KEY_CHARS) {
        max_hash += N_KEY_CHARS * w;
    }
    KEYS = new int[max_hash + 1];
    std::fill_n(KEYS, max_hash, 0);
}

void Dict::insert(char *key) {
    KEYS[ to_hash(key) ] = true;
}

bool Dict::has(char *key) {
    return KEYS[ to_hash(key) ];
}

int Dict::char_to_id(char c) {
    switch (c) {
        case 'A': return 1;
        case 'C': return 2;
        case 'G': return 3;
        case 'T': return 4;
    }
    return 0;
}

int Dict::to_hash(char *key) {
    int hash = 0;
    int w = 1;
    for (int i = 0; key[i]; i++, w *= N_KEY_CHARS) {
        hash += w * char_to_id(key[i]);
    }
    return hash;
}

int main() {
    int n_ops;
    scanf("%d", &n_ops);

    Dict dict;
    char op[10], key[MAX_KEY_LENGTH + 1];

    for (int i = 0; i < n_ops; i++) {
        scanf("%s %s", op, key);
        switch (op[0]) {
            case 'i': // insert
                dict.insert(key);
                break;
            case 'f': // find
                puts( dict.has(key) ? "yes" : "no" );
                break;
        }
    }

    return 0;
}

Measured memory_bytes: 90504
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

pub fn lower_bound<T: Ord>(a: &Vec<T>, x: &T) -> usize {
    use std::cmp::Ordering;
    let mut l = 0;
    let mut r = a.len();
    while l != r {
        let m = l + (r - l) / 2;
        match a[m].cmp(x) {
            Ordering::Less => l = m + 1,
            Ordering::Equal | Ordering::Greater => r = m,
        }
    }
    l
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      s: chars,
      t: chars,
    }

    let n = s.len();
    let mut next = vec![vec![]; n*2];
    let mut table = vec![-1; 28];
    for i in (0..n*2).rev() {
        next[i] = table.clone();
        let c = s[i%n];
        let idx = (c as u8 - 'a' as u8) as usize;
        table[idx] = i as i64;
    }

    let mut ans = 0;
    let mut cur = &table;
    for c in t {
        let idx = (c as u8 - 'a' as u8) as usize;
        let next_idx = cur[idx];
        if next_idx == -1 {
            return puts!("{}\n", -1);
        }
        let next_idx = next_idx as usize;
        ans = ans/n*n + next_idx;
        cur = &next[ (next_idx as usize) % n];
    }
    puts!("{}\n", ans+1);
}


Measured memory_bytes: 55548
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	class T implements Comparable<T>{
		int start, arrive;
		T(int s, int a) {
			this.start = s;
			this.arrive = a;
		}
		@Override
		public int compareTo(T obj) {
			if (this.start < obj.start) return -1;
			else if (this.start > obj.start) return 1;
			return 0;
		}
	}
	
	
	void run() {
		int n;
		StringTokenizer st;
		while (true) {
			n = Integer.parseInt(sc.nextLine());
			if (n == 0) break;
			T[] time = new T[n];
			for (int i = 0; i < n; i++) {
				st = new StringTokenizer(sc.nextLine(), ": ");
				time[i] = new T(Integer.parseInt(st.nextToken())*60*60+Integer.parseInt(st.nextToken())*60+Integer.parseInt(st.nextToken()),
								Integer.parseInt(st.nextToken())*60*60+Integer.parseInt(st.nextToken())*60+Integer.parseInt(st.nextToken()));	
//				out.printf("%d %d\n", time[i].start, time[i].arrive);
			}
			Arrays.sort(time);
			int count = 0;
			boolean[] check = new boolean[n];
			for (int i = 0; i < n; i++) {
				if (!check[i]) {
					count++;
					int pre = i, next = i+1;
					while (next < n) {
						if (!check[next] && time[pre].arrive <= time[next].start) {
							check[next] = true;
							pre = next;
							next++;
						} else {
							next++;
						}
					}
				}
			}
			out.println(count);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 113252
n, k = map(int, input().split())
a = []
for i in range(k):
    d = int(input())
    a.append([d, list(map(int, input().split()))])
c = 0
for i in range(1, n+1):
    for j in a:
        if i in j[1]:
            break
    else:
        c += 1
print(c)


Measured memory_bytes: 9276
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    a,b,c,d=map(int,input().split())
    if a+b>c+d:
        print('Left')
    elif a+b==c+d:
        print('Balanced')
    else:
        print('Right')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>

using namespace std;


const int N = 100;

int b[N];

int main()
{
    //freopen("input.txt", "r", stdin);


    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; ++i)
        scanf("%d", b + i);
    int ans = b[1] + b[n - 1];
    for (int i = 1; i < n - 1; ++i)
        ans += min(b[i], b[i + 1]);

    printf("%d", ans);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[4];
int main()
{
	int i;
	for(i=1;i<=3;i++){
		cin>>a[i];
	}
	sort(a+1,a+4);
	if((a[2]-a[1])==(a[3]-a[2])){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
    return 0;
}

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

int main(){
    double w,h,x,y;
    int center = 0;
    cin >> w >> h >> x >> y;
    if ((x == w/2)&&(y == h/2)){
        center = 1;
    }
    double c;
    c = w*h/2;
    cout << c << ' '<<center << endl;

}



Measured memory_bytes: 256
import java.util.*;
import java.math.*;

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

    Map<Integer, Set<Integer>> edge = new HashMap<>();
    for (int i = 0; i < M; i++) {
      Integer key = Integer.valueOf(x[i]);
      if (!edge.containsKey(key)) {
        edge.put(key, new HashSet<>());
      }
      edge.get(key).add(y[i]);
    }

    int[] memo = new int[N + 1];
    Arrays.fill(memo, -1);

    int ans = 0;
    for (int xi = 1; xi < N + 1; xi++)
      ans = Math.max(ans, count(edge, memo, xi));

    System.out.println(ans);
  }

  private static int count(Map<Integer, Set<Integer>> edge, int[] memo, int xi) {
    if (memo[xi] != -1) return memo[xi];
    int count = 0;
    Set<Integer> dest = edge.get(xi);
    if (dest != null)
      for (int yi : dest)
        count = Math.max(count, (memo[yi] != -1 ? memo[yi] : count(edge, memo, yi)) + 1);
    memo[xi] = count;
    return count;
  }
}

Measured memory_bytes: 96800
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e5 + 11;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll idx, ll val){
	if(start == end)
		segtree[node] += val;
	else{
		ll mid=(start + end)/2;
		if(idx <= mid)
			update(left(node), start, mid, idx, val);
		else
			update(right(node), mid+1, end, idx, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

ll func(ll x){
	return (x*(x+1))/2;
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	ll mx = 0;
	for(ll i=1; i*i <= m; i++){
		if(m%i == 0){
			if(m/i >= n)
				mx = max(i, mx);
			if(i >= n)
				mx = max(m/i, mx);
		}
	}
	cout << mx;
	return 0;
}

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

uint64_t l[87];
int main(){
    l[0] = 2;
    l[1] = 1;

    for(int i=2; i<=86; i++){
        l[i] = l[i-1] + l[i-2];
    }

    int x;
    cin >> x;
    cout << l[x] << endl;


}


Measured memory_bytes: 3512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	ll n, m;
	cin >> n >> m;

	vector<ll> l(m), r(m);
	vector<ll> hor(n + 1, 0);
	rep(i, m)
	{
		cin >> l[i] >> r[i];
		hor[l[i] - 1]++; hor[r[i]]--;
	}

	for (int i = 1; i < n; i++)
	{
		hor[i] += hor[i - 1];
	}
	ll ans = 0;
	rep(i, n)
	{
		if (hor[i] == m)
			ans++;
	}
	cout << ans << endl;

}

Measured memory_bytes: 2560
from collections import deque

N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

st = deque([[i] for i in range(N, 0, -1)])
ord = 0
a = 0
b = 0
while(len(st) > 0):
    if a > 0 and b > 0: break
    now = st.pop()
    if len(now) == N:
        ord += 1
    if P == now:
        a = ord
    if Q == now:
        b = ord
    for i in range(N, 0, -1):
        if i in now: continue
        st.append(now + [i])

print(abs(b - a))

Measured memory_bytes: 3316
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    int[] count = new int[100000];

    for (int i = 0; i < N; i++) {
      int a_ = Integer.valueOf(sc.next());
      count[a_]++;
    }

    sc.close();

    long mod = 1000000000 + 7;

    // Nが偶数の場合はtrue、奇数の場合はfalse
    boolean isEven = false;

    if (N % 2 == 0) {
      isEven = true;
    }

    if (isEven) {

      for (int i = 0; i < 100000; i++) {
        if (i == 0) {
          if (count[i] != 0) {
            System.out.println(0);
            return;
          }
        } else {
          if (i < N) {
            if (i % 2 == 1) {
              if (count[i] != 2) {
                System.out.println(0);
                return;
              }
            } else {
              if (count[i] != 0) {
                System.out.println(0);
                return;
              }
            }
          } else {
            if (count[i] != 0) {
              System.out.println(0);
              return;
            }
          }
        }
      }

    } else {

      for (int i = 0; i < 100000; i++) {
        if (i == 0) {
          if (count[i] != 1) {
            System.out.println(0);
            return;
          }
        } else {
          if (i < N) {
            if (i % 2 == 0) {
              if (count[i] != 2) {
                System.out.println(0);
                return;
              }
            } else {
              if (count[i] != 0) {
                System.out.println(0);
                return;
              }
            }
          } else {
            if (count[i] != 0) {
              System.out.println(0);
              return;
            }
          }
        }
      }

    }

    long[] result = new long[N];

    if (isEven) {
      
      result[0] = 2;
      
      if (2 < N) {
        result[2] = 4;
      }
      
      for (int i = 3; i < N; i++) {
        if (i%2 == 1) {
          result[i] = result[i-1];
        } else {
          result[i] = result[i-1] * 2 % mod;
        }
      }

    } else {
      
      result[0] = 1;
      
      if (1 < N) {
        result[1] = 2;
      }

      for (int i = 2; i < N; i++) {
        if (i%2 == 0) { 
          result[i] = result[i-1];
        } else {
          result[i] = result[i-1] * 2 % mod;
        }
      }

    }

    System.out.println(result[N-1]);

  }

}

Measured memory_bytes: 49696
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m;

struct s_node
{
	int ii;
	int jj;
}stu[55];

struct c_node
{
	int ii;
	int jj;
}check[55];

int dis(int i1,int j1,int i2,int j2)
{
	return abs(i1-i2)+abs(j1-j2);
}

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)  cin>>stu[i].ii>>stu[i].jj;
	for (int i=1;i<=m;i++)  cin>>check[i].ii>>check[i].jj;
	
	for (int i=1;i<=n;i++)
	{
		int minv=1e9+7,pos;
		for (int j=1;j<=m;j++)
		{
			if (dis(stu[i].ii,stu[i].jj,check[j].ii,check[j].jj)<minv)
			{
				minv=dis(stu[i].ii,stu[i].jj,check[j].ii,check[j].jj);
				pos=j;	
			}
		}
		cout<<pos<<endl;
	} 
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum =0;
		String s = sc.next();
		for (int i=0;i<s.length();i++) {
			sum +=s.charAt(i)-'0';
		}
		if (sum %9==0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int ans=0;
void allCombinations(int arr[], int sol[], int start, int end, 
                     int index, int r);
 
void printCombination(int arr[], int n, int r)
{
    int sol[r];
    allCombinations(arr, sol, 0, n-1, 0, r);
}

void allCombinations(int arr[], int sol[], int start, int end,
                     int index, int r)
{
    if (index == r)
    {
        int a,b,c;
        a=sol[0];
        b=sol[1];
        c=sol[2];
        if (a!=b && b!=c && a!=c)
            if (a + b > c && a + c > b && b + c > a) 
                ans++;

        return;
    }
    for (int i=start; i<=end && end-i+1 >= r-index; i++)
    {
        sol[index] = arr[i];
        allCombinations(arr, sol, i+1, end, index+1, r);
    }
}
int main()
{
    int nn;
    cin>>nn;
    int arr[nn];
    for(int i=0 ; i<nn ; ++i)
        cin>>arr[i];
    int r = 3;
    int n = sizeof(arr)/sizeof(arr[0]);
    printCombination(arr, n, r);
    cout<<ans;
}

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

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    
    rep(i, X) r.push_back(p[i]);
    rep(i, Y) r.push_back(q[i]);
    sort(r.rbegin(), r.rend());
    cout << accumulate(r.begin(), r.begin() + X + Y, 0LL) << endl;
}

Measured memory_bytes: 2552
def read_i
  gets.chomp.split(' ').map(&:to_i)
end

n, m, c = read_i
bs = read_i
ass = n.times.map { read_i }

count = 0
ass.each do |as|
  total = as.zip(bs).reduce(c) do |acc, (a, b)|
    acc + a * b
  end
  count += 1 if total > 0
end

puts count

__END__
2 3 -10
1 2 3
3 2 1
1 2 2


Measured memory_bytes: 1916
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_bacq
#define MP maqe_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int dp[310][310];

int main()
{
	int n;
	
	while(cin >> n,n)
	{
		REP(i,310)REP(j,310)dp[i][j] = 0;
		
		vector<int> v(n);
		REP(i,n)cin >> v[i];
		
		REP(i,n-1)if(abs(v[i]-v[i+1]) < 2)dp[i][i+1] = 2;
		
		for(int q = 2;q < n;q++)
		{
			for(int i = 0;i+q < n;i++)
			{
				int j = i+q;
				for(int k = 0;k < j-i;k++)
				{
					dp[i][j] = max(dp[i][j],dp[i][i+k]+dp[i+k+1][j]);
				}
				if(dp[i+1][j-1] == j-i-1)
				{
					int tmp = 0;
					if(abs(v[i]-v[j])<2)tmp = 2;
					dp[i][j] = max(dp[i][j],j-i-1+tmp);
				}
			}
		}
		
		cout << dp[0][n-1] << endl;
		
	}
	
	
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  string M;
  cin >> M;
  int s1=0;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    if(M[i]=='W'){
     vec[i]=0;
    }
    else{
     vec[i]=1;
    }
    s1+=vec[i];
  }
  int ans=pow(10,6),s=s1;
  for(int i=0;i<N;i++){
    if(i==0){
      s=s-vec[i];
    }
    if(i>0){
      s=s-vec[i]+(1-vec[i-1]);
    }
    ans=min(ans,s);
  }
  
  cout << ans <<endl;
}

  

Measured memory_bytes: 4776
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

#define LLINF (1LL<<60)
using ll = long long;
#define mod  1000000007

#define whole(a) (a).begin(),(a).end()
#define rwhole(a) (a).rbegin(),(a).rend()

#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(ll i=(a);i>=(b);i--)
#define each(itr,ds) for(auto itr=(ds).begin();itr!=(ds).end();itr++)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";each(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";each(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm,char t){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,char t,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);if(t=='\n') cerr<<"  "<<name<<"\t: "<<x<<t;else cerr << name<<": "<<x<<","<<t;dump_f(nx,t,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,char t,Ts&&... ts){cerr<<"[ln: "<<ln<<"]"<<t;dump_f(nm,t,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\n',__VA_ARGS__)
#define dl(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\t',__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(whole(V),c))

int main() {
    ios::sync_with_stdio(false);//printf<=>cout
    cin.tie(nullptr);//cin<=>cout


    ll N,K;
    cin >>N>>K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(whole(A));
    ll ans = 0;
    rep(i,K) ans+=A[i];
    cout << ans <<'\n';


    return (0);
}

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

int main() {
	char s[200001];
	scanf("%s", s);
	int right = 0;
	int left = 0;
	for(int i = 0; i < (int)strlen(s); i++) {
		if(s[i] == 'Z') {
			right = i;
		}
	}
	for(int i = strlen(s) - 1; i >= 0; i--) {
		if(s[i] == 'A') {
			left = i;
		}
	}
	printf("%d\n", right - left+ 1);
}

Measured memory_bytes: 384
module kkk
  sub main()
    
    dim nm() as integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine.Split(" "), AddressOf Integer.Parse)
    dim n as long = nm(0)
    dim m as long = nm(1)
    dim a as string
    
    if n = m then 
      a = "Yes"
    else
      a = "No"
    end if
    
    console.writeline(a)
    
  end sub
end module

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int n,k,a[300001];
long long s;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n-k;i++){
		s+=a[i];
	}
	cout<<s;
}



Measured memory_bytes: 1024
#include <stdio.h>
#define MOD 1000000007
#define N 100000

int main() {
	int num,i,j=0;
	long A[N];
	long count=1;
	int hat[3]={0,0,0};
	int hatnum=0;
	scanf("%d",&num);
	for(i=0; i<num; i++) {
    	scanf("%ld", &A[i]);
    }
	for(i=0; i<num; i++) {
		if(A[i]==hat[0]) {
			hatnum++;
			j=0;
		}
		if(A[i]==hat[1]) {
			hatnum++;
			j=1;
		}
		if(A[i]==hat[2]) {
			hatnum++;
			j=2;
		}
		switch(hatnum) {
			case 0:
				printf("0");
				return 0;
				break;
			case 1:
				break;
			case 2:
				count*=2;
				break;
			case 3:
				count*=3;
				break;
			default :
				printf("0");
				return 0;
				break;
		}
		hat[j]++;
		hatnum=0;
		if(count>MOD) {
			count %= MOD;
		}
	}
	printf("%ld",count);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    long double a, b, c;
    cin >> a >> b >> c;

    long double eps = 1.0E-14;
    if (sqrt(a) + sqrt(b) + eps< sqrt(c)) cout << "Yes" << endl;
    else cout << "No" << endl;    

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

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

int main(){
  string s;
  cin >> s;
  //cin >> t;
  sort(s.begin(), s.end());
  if(s.at(0)!=s.at(2)){
    if(s.at(0)==s.at(1)&&s.at(2)==s.at(3)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
const int N = 1010,mod = 1e9+7;
typedef long long LL;
 
int n,m;
int dp[N][N];
char g[N][N];
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    for(int i = 1; i<=n; i++)
        for(int j = 1; j<=m; j++) cin>>g[i][j];
    
    
    dp[1][1] = 1;
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=m; j++){
            if(g[i-1][j] == '.') dp[i][j] = (dp[i][j] + dp[i-1][j]) %mod;
            if(g[i][j-1] == '.') dp[i][j] = (dp[i][j] + dp[i][j-1]) %mod;
        }
    }
    
    cout<<dp[n][m];
    return 0;
}

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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	int a,b,c;
	cin>>a>>b>>c;
	cout<<b+min(c,a+b+1);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;
ll inf=1LL<<60;
double eps=1e-14;

const int V = 100005;
vector<int> to[V*2];
bool visited[V*2];

vector<int> cnt;

void dfs(int v)
{
    if(visited[v]) return ;
    visited[v] = true;
    cnt[v/V]++;
    for(int u:to[v]) dfs(u);
}

int main()
{
    int n;
    cin >> n;
    rep(i,0,n)
    {
        int x, y;
        cin >> x >> y;
        y += V;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    ll ans = 0;
    rep(i,0,V*2)
    {
        if(visited[i]) continue;
        cnt = vector<int>(2);
        dfs(i);
        ans += (ll)cnt[0]*cnt[1];
    }
    ans -= n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll ans=0;
ll n;

	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

ll n,a,b,c,d;
string s;
cin>>n>>a>>b>>c>>d;
cin>>s;

ll snuke[n+1]={0};
ll fnuke[n+1]={0};
snuke[a-1]=1;

for(ll i=a;i<=c-1;i++)
{
	if(s[i]=='#')
		snuke[i]=0;
	else
		{	if(i==1)
			snuke[i]=snuke[i-1];
			else
			snuke[i]=snuke[i-1]+snuke[i-2];
	}
}

fnuke[b-2]=0;
fnuke[b-1]=1;

for(ll i=b;i<=d-1;i++)
{
	if(s[i]=='#')
		fnuke[i]=0;
	else
		fnuke[i]=fnuke[i-1]+fnuke[i-2];
}

if(snuke[c-1]==0 || fnuke[d-1]==0 )
	cout<<"No"<<endl;

else
{
	if(c<d)
		cout<<"Yes"<<endl;
	else
		{	for(ll i=b-2;i<=d-2;i++)
			{
				if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.')
					ans++;
			}

			if(ans)
				cout<<"Yes"<<endl;
			else
				cout<<"No"<<endl;
		}
}

}	





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

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

  // 1.の出力
if (a==b && b==c)
{cout << "Yes" << endl;}
  // ここにプログラムを追記

else {cout << "No" << endl;}
}

Measured memory_bytes: 3584
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[][][] count = new int[4][3][10];
    int n = sc.nextInt();
    for (int i = 0; i < n; i++) {
      int b = sc.nextInt();
      int f = sc.nextInt();
      int r = sc.nextInt();
      int v = sc.nextInt();
      count[b - 1][f - 1][r - 1] += v;
    }
    for (int i = 0; i < count.length; i++) {
      for (int j = 0; j < count[i].length; j++) {
        for (int k = 0; k < count[i][j].length; k++) {
          System.out.print(" " + count[i][j][k]);
        }
        System.out.println();
      }
      if (i < count.length - 1) {
        for (int j = 0; j < 20; j++) {
          System.out.print('#');
        }
        System.out.println();
      }
    }
  }
}


Measured memory_bytes: 29840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            int n = Integer.parseInt(line);
            int m = n - 1;
            boolean[] ns = new boolean[n + 1];

            for (int i = 2; i < n + 1; i++) {
                if (ns[i])
                    continue;
                for (int j = 2; j < n / i + 1; j++) {
                    if (!ns[i * j]) {
                        //System.out.println(i * j);
                        ns[i * j] = true;
                        m--;
                    }
                }
            }
            System.out.println(m);
        }
    }
}

Measured memory_bytes: 34800
#include <stdio.h>


int main()
{
    int a,h,m,s;
        
    scanf("%d", &a);
    h=a/60/60;
    m=(a-h*3600)/60;
    s=a-(h*3600)-(m*60);
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
        
}




Measured memory_bytes: 2148
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX_R 1001
#define MAX_N 201
#define inf (1<<29)
using namespace std;
struct P
{
  int to,cost;
  char c;
  P(int to=0,int cost=0,char c='x'):to(to),cost(cost),c(c){}
};
typedef vector<P> VP;
typedef vector<VP> VVP;
int N,M,R;
int LG[MAX_N][MAX_N];
int SG[MAX_N][MAX_N];
int dp[MAX_R][MAX_N];//dp[i][j] := 集配先

int main()
{
  while(cin >> N >> M,N|M)
    {
      rep(i,MAX_N)rep(j,MAX_N)LG[i][j] = SG[j][i] = (i==j?0:inf);
      rep(i,MAX_R)rep(j,MAX_N)dp[i][j] = inf;
      VVP G(N);
      rep(i,M)
	{
	  int x,y,t;
	  char c;
	  cin >> x >> y >> t >> c;
	  x--,y--;
	  G[x].push_back(P(y,t,c));
	  G[y].push_back(P(x,t,c));
	  if(c == 'L')LG[y][x] = LG[x][y] = min(LG[y][x],t);
	  if(c == 'S')SG[y][x] = SG[x][y] = min(SG[x][y],t);
	}

      cin >> R;
      vector<int> v(R);
      rep(i,R)
	{
	  cin >> v[i];
	  v[i]--;
	}

      for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)LG[i][j] = min(LG[i][j],LG[i][k]+LG[k][j]),SG[i][j] = min(SG[i][j],SG[i][k]+SG[k][j]);
      dp[0][v[0]] = 0;

      /*
      cout << "-----------" << endl;
      rep(i,N)
	{
	  rep(j,N)cout << SG[i][j] << " ";
	  cout << endl;
	}
      */
      rep(i,R-1)
	{
	  rep(j,N)
	    {
	      if(dp[i][j] == inf)continue;

	      //cout << "dp["<<i<<"]["<<j<<"] ------- "<< dp[i][j] << endl;
	      dp[i+1][j] = min(dp[i+1][j],
			       dp[i][j]+LG[v[i]][v[i+1]]);
	      //cout << "dp["<<i+1<<"]["<<j<<"] = " << dp[i+1][j]  << " | " << dp[i][j] << "+" << LG[v[i]][v[i+1]]<< endl; 
	      rep(k,N)
		{
		      dp[i+1][k] = min(dp[i+1][k],
					   dp[i][j] + SG[j][k] + LG[v[i]][j] + LG[k][v[i+1]]);
		      //cout << v[i] << " dp["<<i+1<<"]["<<k<<"] = " << dp[i+1][k] << " | " << dp[i][j] << "+" << SG[v[i]][k] << "+" << LG[k][v[i+1]] << endl;
		      
		}
	    }
	}

      int minCost = (1<<29);
      rep(i,N)minCost = min(minCost,dp[R-1][i]);
      cout << minCost << endl;
    }
  return 0;
}

Measured memory_bytes: 2632
//  s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま
//  s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま
//s配列に格納した単語を、辞書順にソートする
//getline(cin, s);
//  sort(s.begin(), s.end());
//  string t = "keyence";//で文字列入力ができる
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
int kan_hyaku(int n){
  int kurai = 0;
  for(int i=0;i<3;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ju(int n){
  int kurai = 0;
  for(int i=0;i<2;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ichi(int n){
  int kurai = 0;
  for(int i=0;i<1;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int main() {
  int n;
  cin >> n;
  vector<ll>a(n);
  vector<ll>b(n);
  rep(i,n) cin>> a.at(i) >> b.at(i);
  ll sum = 0;
  for(int i=0;i<n;i++){
    ll k = n - i - 1;
    ll po = b.at(k) - (a.at(k) + sum ) % b.at(k);
    if(po < b.at(k)){
      sum += po;
    }
  }
  cout << sum << endl;
}
/*
  for(int i=n-1;i>=0;i--){
    if(a.at(i)+sum <= b.at(i) ){
      sum += b.at(i) - (a.at(i)+sum);
    }
    else{
      ll num = (a.at(i)+sum) % b.at(i);
      if(num != 0){
        sum += b.at(i) - num;
      }
    }
  }
  cout << sum << endl;
}
*/

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

int main()
{
	string str;
	while(getline(cin, str)){
		if(str[0] == '0')
			break;
		stringstream sst;
		sst << str;
		int a;
		int sum = 0;
		int onecount = 0;
		while(sst >> a){
			if(a == 1){
				sum += 1;
				onecount++;
			}
			else if(a > 10){
				sum += 10;
			}else{
				sum += a;
			}
		}
		if(sum > 21)
			sum = 0;
		else{
			while(true){
				if(sum+10 <= 21 && onecount!=0){
					sum += 10;
					onecount--;
				}
				else
					break;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 7))

MOD = pow(10, 9) + 7
ans = 1
n, k = map(int, input().split())
visited = [False for _ in range(n)]
edges = {}

def dfs(i, c1, c2):
  global ans
  if visited[i]:
    return
  visited[i] = True
  ans = ans * (k-c1-c2) % MOD
  c0 = 0
  for e in edges[i]:
    if not visited[e]:
      dfs(e, 1, c1+c0)
      c0 += 1


def main():
  for _ in range(n-1):
    a, b = map(int, input().split())
    if a-1 not in edges:
      edges[a-1] = [b-1]
    else:
      edges[a-1].append(b-1)
    if b-1 not in edges:
      edges[b-1] = [a-1]
    else:
      edges[b-1].append(a-1)
  # start
  if n == 1:
    print(k)
  else:
    for i in range(n):
      if len(edges[i]) == 1:
        dfs(i, 0, 0)
    print(ans)


if __name__ == '__main__':
  main()


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h) cin >> a[i];
  int sum = 0;
  rep(i, h) rep(j, w) if(a[i][j] == '#') ++sum;
  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<P> q;
  auto update = [&](P now) {
    int i = now.first, j = now.second;
    rep(k, 2) {
      int ni = i+di[k], nj = j+dj[k];
      if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if(dist[ni][nj] == INF) {
        dist[ni][nj] = dist[i][j] + 1;
        q.push(P(ni, nj));
      }
    }
  };

  dist[0][0] = 1;
  q.push(P(0, 0));

  while(!q.empty()) {
    P now = q.front(); q.pop();
    update(now);
  }

  if(dist[h-1][w-1] == sum) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
import sys
s = input()
l =[['k','eyence'],['ke','yence'],['key','ence'],['keye','nce'],['keyen','ce'],['keyenc','e']]

if s.startswith('keyence') or s.endswith('keyence'):
    print('YES')
else:
    for i in l:
        tmps = s
        if s.startswith(i[0]) and s.endswith(i[1]):
            print('YES')
            sys.exit(0)
    else:
        print('NO')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

const long long eps = 100000;

long long n, a[100005], b[100005], ans;
long long sum[100005], num[200005];

long long check(long long x) {
  long long res = 0;
  memset(sum, 0, sizeof(sum));
  memset(num, 0, sizeof(num));
  for(int i = 1; i <= n; i++) {
    if(a[i] >= x) sum[i] = sum[i - 1] + 1;
    else sum[i] = sum[i - 1] - 1;
  } long long pre = 0; num[eps] = 1;
  for(int i = 1; i <= n; i++) {
    if(sum[i] > sum[i - 1])
      pre += num[sum[i] + eps] + 1;
    else pre -= num[sum[i - 1] + eps] - 1;
    num[sum[i] + eps]++; res += pre;
  } return res;
}

int main() {
  //  freopen("a.in", "r", stdin);
  scanf("%lld", &n);
  for(long long i = 1; i <= n; i++)
    scanf("%lld", &a[i]), b[i] = a[i];
  sort(b + 1, b + n + 1);
  long long m = unique(b + 1, b + n + 1) - b - 1;
  long long l = 1, r = m;
  long long num = n * (n + 1) / 2 - n * (n + 1) / 2 / 2;
  while(l <= r) {
    long long mid = (l + r) >> 1;
    long long mem = check(b[mid]);
    if(mem >= num) {
      ans = b[mid]; l = mid + 1;
    } else r = mid - 1;
  } printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4096