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

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    cin>>n;
    cout<<n/3<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

float N, D;

int main() {
    cin >> N >> D;
    cout << ceil(N / (D * 2 + 1)) << endl;
    return 0;
}


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

int main() {
	int k;
	cin >> k;
	vector<int> a(k);
	for (int i = 0; i < k; i++) {
		cin >> a[i];
	}
	if (a[k - 1] == 2) {
		ll m = 2, n = 2 * 2 - 1;
		for (int i = k - 2; i >= 0 && m <= n; i--) {
			m = ((m - 1) / a[i] + 1) * a[i];
			n = (n / a[i] + 1) * a[i] - 1;
			// cout << m << " " << n << endl;
		}
		if (m <= n) {
			cout << m << " " << n << endl;
		} else {
			cout << -1 << endl;
		}
	} else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {



	public static void bubble_sort(int[] a) {
		int num_swaps = 0;
		for (int i = 0; i < a.length; i++) {
			for (int j = a.length - 1; j >= i+1; j--) {
				if (a[j] < a[j-1]) {
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					num_swaps++;
				}
			}
		}
		display(a);
		System.out.println(num_swaps);
	}

	public static void display(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length - 1)
				System.out.print(" ");
			else
				System.out.print("\n");
		}
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		bubble_sort(a);
	}

}



Measured memory_bytes: 26236
#include <bits/stdc++.h>
using namespace std;
    
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 10000002
#define MOD 1000000007
    
signed main() {
    int n, m;
    cin >> n >> m;
    vvi v(n, vi(2));
    for(int i = 0; i < n; i++) cin >> v[i][0] >> v[i][1];
    sort(v.begin(), v.end());
    int cost = 0;
    for(int i = 0; i < n; i++) {
        cost += (v[i][0] * min(m, v[i][1]));
        m -= v[i][1];
        if(m <= 0)  break;
    }
    cout << cost << endl;        
}

Measured memory_bytes: 5760
use std::cmp;

#[allow(dead_code)]
pub struct Scanner<'a> {
    _buf: &'a str,
    iter: ::std::str::SplitWhitespace<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(buf: &'a str) -> Self {
        Scanner {
            _buf: buf,
            iter: buf.split_whitespace(),
        }
    }

    pub fn array<T>(&mut self, n: usize) -> Vec<T>
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.value());
        }
        res
    }

    pub fn value<T>(&mut self) -> T
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.next().chars().collect()
    }

    fn next(&mut self) -> &str {
        self.iter.next().unwrap()
    }
}

struct Solver {
    k: i64,
    a: Vec<i64>,
    memo: Vec<Option<i64>>,
}

impl Solver {
    fn new(k: i64, a: Vec<i64>) -> Self {
        let n = a.len();
        Solver {
            k: k,
            a: a,
            memo: vec![None; n],
        }
    }

    fn f(&mut self, x: i64) -> i64 {
        if x == 0 { return 0; }

        if self.memo[x as usize].is_none() {
            let mut res = 10_i64.pow(18);
            let start = cmp::max(0, x-self.k);
            for i in start..x {
                let c = self.f(i) + cost(self.a[i as usize], self.a[x as usize]);
                res = cmp::min(res, c);
            }
            self.memo[x as usize] = Some(res);
        }
        self.memo[x as usize].unwrap()
    }

    /*
    fn f(&mut self, k: i64) -> i64 {
        if k == 0 { return 0; }
        if k == 1 { return cost(self.a[0], self.a[1]); }

        if self.memo[k as usize].is_none() {
            let c1 = self.f(k-1) + cost(self.a[(k-1) as usize], self.a[k as usize]);
            let c2 = self.f(k-2) + cost(self.a[(k-2) as usize], self.a[k as usize]);
            self.memo[k as usize] = Some(cmp::min(c1, c2));
        }
        self.memo[k as usize].unwrap()
    }
    */
}

fn cost(h1: i64, h2: i64) -> i64 {
    (h1-h2).abs()
}

fn main() {
    let mut _input = String::new();
    {
        use ::std::io::Read;
        ::std::io::stdin().read_to_string(&mut _input).unwrap();
    }
    let mut sc = Scanner::new(&_input);

    let n = sc.value::<i64>();
    let k = sc.value::<i64>();
    let a = sc.array::<i64>(n as usize);

    let mut sol = Solver::new(k, a);
    let ans = sol.f(n-1);

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


Measured memory_bytes: 11004
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
P = 10**9
N = int(input())
LR = [ inpl() for _ in range(N) ]
LR.sort()

K = 0
mlist = []
for i in range(N):
    l, r = LR[i]
    k = r -l + 1
    if k == K:
        mlist.append(i)
    elif k > K:
        mlist = [i]
        K = k
U = []
r = P
for i in range(N):
    l = LR[i][0]
    r = min(r, LR[i][1])
    U.append((l,r))
D = [None]*N
l = LR[-1][0]
for i in range(N):
    r = min(r, LR[N-1-i][1])
    D[N-1-i] = (l,r)

ans = K
for m in mlist:
    if m == 0:
        score = K + max(0, D[1][1]-D[1][0]+1)
    elif m == N-1:
        score = K + max(0, U[-2][1]-U[-2][0]+1)
    else:
        score = K + max(0, min(U[m-1][1],D[m+1][1]) - D[m+1][0] + 1)
    if score > ans:
        ans = score

LR2 = []
for i in range(N):
    while LR2 and LR2[-1][1] >= LR[i][1]:
        LR2.pop()
    LR2.append(LR[i])
M = len(LR2)
if M < 2:
    print(ans)
    exit()

R1 = LR2[0][1]
L2 = LR2[-1][0]
for i in range(M-1):
    L1 = LR2[i][0]
    R2 = LR2[i+1][1]
    score = max(0, R1-L1+1) + max(0, R2-L2+1)
    if score > ans:
        ans = score

print(ans)

Measured memory_bytes: 71004
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define MP(x,y) make_pair(x,y)
#define ARRAY 65536
#define X first
#define Y second
#define DBG 0
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
      std::fill( (T*)array, (T*)(array+N), val );
}

int dp[(1<<16)] = {0};
int memo[(1<<16)][128] = {0};
int sumn[(1<<16)] = {0};

int main(void){
  int n, m;
  while(cin >> n >> m, n){
    vector<int> s;
    vector<int> d;
    Fill(dp, 1000000000);
    Fill(memo, 0);
    Fill(sumn, 0);
    s.resize(n);
    d.resize(m);

    for(auto& ss: s) cin >> ss;
    for(auto& dd: d) cin >> dd;

    rep(state, (1<<n)){
      rep(i, n){
        int mask = 1<<i;
        if((state|mask) == state){
          sumn[state] += s[i];
        }
      }
    }

    dp[0] = 0;
    rep(i,m) dp[0] += d[i];
    Fill(dp, dp[0]);


    rep(state, (1<<n)-1){
      rep(i,n){
        vector<int> use;
        int mask = 1<<i;
        int f = 0;
        if((state | mask) == state) continue;
        rep(j, m){
          if( memo[state][j] == sumn[state] ){
            if( abs(d[j] - memo[state][j] - s[i]) < abs(d[j] - memo[state][j])){
              use.push_back(j);
              f += abs(d[j] - memo[state][j]) - abs(d[j] - memo[state][j] - s[i]);
            }
          }
        }

        if(dp[state|mask] > dp[state]-f){
          dp[state|mask] = dp[state]-f;
          rep(j,m)
            memo[state|mask][j] = memo[state][j];
          rep(j, use.size())
            memo[state|mask][use[j]] += s[i];
        }
      }
    }

    cout << dp[(1<<n)-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 36396
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, R;
    cin >> N >> R;
    if(N >= 10){
        cout << R << endl;
    }else{
        cout << R + 100 * (10 - N) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A+B < C+D){
    cout << "Right" << endl;
  }
  else if(A+B == C+D){ 
    cout << "Balanced" << endl;
  }
  else { 
    cout << "Left" << endl;
  }
}

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

using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  cin.ignore();
  int sum = 0;
  vector <int> d;
  int tmp;
  for (int i = 0; i < n; i++){
    cin >> tmp;
    sum += tmp;
    d.push_back(tmp);
  }

  ll ans = 0;
  for (int i = 0; i < n - 1; i++){
    tmp = d[i];
    sum -= d[i];
    ans += tmp * sum;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int r, c;
    cin >> r >> c;
    vector<string> v(r);
    for(int j = 0; j < r; j++) cin >> v[j];
    vector<int> prv(c+1, 0);
    prv[1] = 1;

    for(int j = 1; j <= r; j++){
        vector<int> cur(c+1, 0);
        for(int k = 1; k <= c; k++){
            if(v[j-1][k-1] == '#') continue;
            cur[k] += prv[k]+cur[k-1];
            cur[k] %= mod;
        }
        // for(auto i : cur) cout << i << " "; cout << endl;
        prv = cur;
    }
    cout << prv[c] << '\n';
    return 0;
}

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

int main() {
  int n = 1;
  char c;
  while (cin.get(c)) {
    if (c == '@') {
      cin >> c;
      n = c - '0';
      continue;
    }
    for (int i=0; i<n; i++) {
      cout << c;
    }
    n=1;
  }
  return 0;
}

Measured memory_bytes: 1100
n = int(input())
ans = [0 for i in range(n)]


for i in range(100):
  for j in range(100):
    for k in range(100):
      a = (i+1)*(i+1) +(j+1)*(j+1) + (k+1)*(k+1) + (i+1)*(j+1) +(j+1)*(k+1) + (k+1)*(i+1)
      if a <= n:
        ans[a-1]+=1
for i in ans:
  print(i)

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

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

  ll n, k;
  cin >> n >> k;
  ll min1 = n % k;
  ll min2 = abs(k - min1);
  cout << min(min1, min2) << endl;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(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, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int[] a = in.readIntArray(n);
            int ans = 0;
            for (int x : a) {
                while (x % 2 == 0) {
                    ans++;
                    x /= 2;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] readIntArray(int size) {
            int[] ans = new int[size];
            for (int i = 0; i < size; i++) ans[i] = readInt();
            return ans;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int main()
{
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    if(a+b*5+c*10+d*50+e*100+f*500>=1000)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	string s;
	for (int i = 0; i < h; i++) {
		cin >> s;
		cout << s << endl << s << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % int(powl(10,9) + 7);
    }

    return f;
}

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

    int v1 = a*b,v2 = c*d;

    cout << (v1 < v2 ? v2 : v1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int maxiA,pointA,N,u,v,A,B,costA[200200],costB[200200],ans=0;
vector<int> G[100100];

void dfsb(int now, int cost){
    costB[now]=cost;
    for(int next:G[now]){
        if(costB[next]==-10){
            dfsb(next,cost+1);
        }
    }

}

void dfsa(int now, int cost){
    costA[now]=cost;
    ans=max(ans,costB[now]-1);
    for(int next:G[now]){
        if((costB[next]>(cost+1))&&costA[next]==-10){
            dfsa(next,cost+1);
        }
    }
}

int main(){
    cin>>N>>u>>v;
    u--;
    v--;
    rep(i,200100){
        costA[i]=-10;
        costB[i]=-10;
    }
    rep(i,N-1){
        cin>>A>>B;
        A--;
        B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    dfsb(v,0);
    dfsa(u,0);
    out(ans);

    
    
}


Measured memory_bytes: 9856
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include <algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define forz(i,a,b) for(int i=(a);i<=(b);i++)
#define forf(i,a,b) for(int i=(a);i>=(b);i--)
#define mems(x,v) memset(x,v,sizeof(x))
using namespace std;
int n,i,j,q,f,x,y,z,Q,ans;
int xds[30][500500];
char s[500500],c;
int lowbit(int x)
{
    return x&(-x);
}
void add(int k,int z,int x)
{
    for(int i=k;i<=n;i+=lowbit(i))
        xds[z][i]+=x;
}
int ask(int k,int z)
{
    int ans=0;
    while(k)
    {
        ans+=xds[z][k];
        k-=lowbit(k);
    }
    return ans;
}
int main()
{
scanf("%d",&n);
scanf("%s",s);
scanf("%d",&Q);
memset(xds,0,sizeof(xds));
for(i=0;i<n;i++)
{
    z=s[i]-'a';
    add(i+1,z,1);
    //cout<<"??"<<ask(i+1,z)<<endl;
}
for(i=0;i<26;i++)
    //cout<<"~~"<<ask(1,i)<<endl;
while(Q--)
{
    scanf("%d",&q);
    if(q==1)
    {
        scanf("%d %c",&x,&c);
        z=c-'a';
        add(x,z,1);
        z=s[x-1]-'a';
        add(x,z,-1);
        s[x-1]=c;
    }
    else
    {
        ans=0;
        scanf("%d%d",&x,&y);
        for(i=0;i<26;i++)
        {
            f=ask(y,i)-ask(x-1,i);
            //cout<<": "<<ask(y,i)<<' '<<ask(x-1,i)<<endl;
            if(f)ans++;
        }
        printf("%d\n",ans);
    }
}
return 0;
}

Measured memory_bytes: 59392
import java.util.Scanner;

class Main{
	static int N;

	static int[] h;

	static int[] memo;

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

		N = sc.nextInt();
		h = new int[N];
		memo = new int[N];
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
			memo[i] = -1;
		}

		int ans = dp(N - 1);

		System.out.println(ans);
		sc.close();
	}

	static int dp(int i) {
		if(i == 0)
			return 0;
		if(memo[i] == -1) {
			int jump1 = Integer.MAX_VALUE,jump2 = Integer.MAX_VALUE;
			jump1 = dp(i - 1) + Math.abs(h[i] - h[i - 1]);
			if(i > 1)
				jump2 = dp(i - 2) + Math.abs(h[i] - h[i - 2]);
			memo[i] = Math.min(jump1, jump2);
		}
		return memo[i];
	}
}

Measured memory_bytes: 68176
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

void func(int N,int A, int B, int C, int X){
	int table[N],index = 0,ans = -1;

	for(int i = 0; i < N; i++)scanf("%d",&table[i]);

	if(X == table[index]){
		index++;
		if(index == N){
			ans = 0;
		}
	}

	if(ans == -1){
		for(int i = 1; i <= 10000; i++){
			X = (A*X+B)%C;
			if(X == table[index]){
				index++;
				if(index == N){
					ans = i;
					break;
				}
			}
		}
	}

	printf("%d\n",ans);
}


int main(){

	int N,A,B,C,X;
	while(true){
		scanf("%d %d %d %d %d",&N,&A,&B,&C,&X);
		if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0)break;

		func(N,A,B,C,X);

	}

	return 0;
}

Measured memory_bytes: 2708
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); scanf().tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007

long long total(long long n){
  return n*(n+1)/2;
}

int main()
{
  long long n;
  cin>>n;
  long long k;
  cin>>k;
  long long ans=0;
  for(long long i=k;i<=n+1;i++)
  {
    ans += ((total(n)-total(n-i)) - total(i-1) +1)%MOD;
  }
  cout<<ans%MOD<<endl;
}


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

int main() {
  int n;
  cin >> n;
  
  bool judge = false;
  for (int i=0; i<9; i++) {
    for (int j=0; j<9; j++) {
      if ((i+1)*(j+1)==n) {
        judge = true;
        break;
      }
    }
  }
  
  if (judge)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll cnt[202020];

int main(){
  int N,K; cin>>N>>K;
  for(int i=1;i<=N;i++) cnt[i%K]++;
  ll ans=cnt[0]*cnt[0]*cnt[0];
  if(K%2==0) ans+=cnt[K/2]*cnt[K/2]*cnt[K/2];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF INT_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef unsigned long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> State;

void solve(){
    int a,b,c,k;cin>>a>>b>>c>>k;
    if(k<=a) cout<<k;
    else if(k<=(a+b)) cout<<a;
    else if(k<=(a+b+c)) cout<<a-(k-a-b);
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

Measured memory_bytes: 3560
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define INFLL 1000000000000000000LL
#define MOD 1000000007
#define PI acos(-1)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>

using namespace std;

// clang-format on

main {
  int n;
  cin >> n;
  int a = 0;
  for (int i = 1;; i++) {
    a += i;
    if (n <= a) {
      cout << i << endl;
      bye;
    }
  }
  bye;
}


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

using ll = long long;
const int INF = 1e9 + 1;


int main(){

	int K, S;
	cin >> K >> S;

	int ans = 0;
	for (int i = 0; i <= K; i++)
		for (int j = 0; j <= K; j++) {
			int k = S - i - j;
			if(0<=k&&k<=K)
				ans++;
		}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
typedef pair<int,int> P; 
const int maxn = 30;
const int INF = 1e9+8;
char c[maxn][maxn];
int n,m;
int a[maxn][maxn];
queue <P> que;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main()
{
	int ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",c[i]+1);
	P p; int x,y,tx,ty;
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=m;j++)
	   {
	   	   if(c[i][j]=='#') continue;
	   	   for(int x=1;x<=n;x++)
	   	      for(int y=1;y<=m;y++)
	   	         a[x][y]=INF;
	   	    que.push(P(i,j));
	   	    a[i][j]=0;
	   	    while(que.size())
	   	    {
	   	    	p=que.front(); que.pop();
	   	    	x=p.first; y=p.second;
	   	    	for(int i=0;i<4;i++)
	   	    	{
	   	    		tx=x+dx[i]; ty=y+dy[i];
	   	    		if(tx<0||tx>n||ty<0||ty>m) continue;
	   	    		if(c[tx][ty]=='#') continue;
	   	    		if(a[tx][ty]!=INF) continue;
	   	    		a[tx][ty]=a[x][y]+1;
	   	    		que.push(P(tx,ty));
	   	    		ans=max(ans,a[tx][ty]);
				}
			}
	   }
	   printf("%d",ans);
	return 0;
} 

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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;
}

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


string S;

void input() {
	cin>>S;
}

void solve() {
	for(int i=0; i<S.len-1; i++) {
		if(S[i]==S[i+1]) {
			cout<<i+1<<" "<<i+2<<endl;
			return;
		}
		if(i<S.len-2 && S[i]==S[i+2]) {
			cout<<i+1<<" "<<i+3<<endl;
			return;
		}
	}
	cout<<-1<<" "<<-1<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3764
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
narr = lambda d, f: narr(d[:-1], lambda: [f() for _ in range(d[-1])]) if d else f() # narr((2,3), int)
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
	s = rs()
	M.append(s)

start = tuple([C[0]-1, C[1]-1])
end = tuple([D[0]-1, D[1]-1])

queue = deque()
queue.append((start, 0))
#visited = narr((H, W), lambda: float('inf'))
visited = [[float('inf')] * W for _ in range(H)]
visited[start[0]][start[1]] = 0

ds = [(1,0),(-1,0),(0,1),(0,-1)]
while queue:
	n, d = queue.popleft()
	if n == end:
		print(d)
		exit()
	i, j = n
	if visited[i][j] != d:
		continue
	nd = d
	for di, dj in ds:
		ni, nj = i+di, j+dj
		if not (0 <= ni < H and 0 <= nj < W): continue
		if M[ni][nj] == '#': continue
		if nd < visited[ni][nj]:
			queue.appendleft(((ni,nj), nd))
			visited[ni][nj] = nd
	nd = d+1
	for di in range(-2, 3):
		for dj in range(-2, 3):
			if (di, dj) == (0,0): continue
			ni, nj = i+di, j+dj
			if not (0 <= ni < H and 0 <= nj < W): continue
			if M[ni][nj] == '#': continue
			if nd < visited[ni][nj]:
				queue.append(((ni,nj), nd))
				visited[ni][nj] = nd
print(-1)


Measured memory_bytes: 101048
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
 
vector<int> cache;
int dp(int index, vector<int>& h) {
  if (index >= h.size()) {
    return 999999;
  }
  if (index == h.size()-1) {
    return 0;
  }
  if (cache[index] != -1) {
    return cache[index];
  }
  cache[index] = min(abs(h[index+2] - h[index]) + dp(index+2, h), abs(h[index+1] - h[index]) + dp(index+1, h));
  return cache[index];
}
 
int main() {
  int n; cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    cache.push_back(-1);
  }
  cout << dp(0, h);
}

Measured memory_bytes: 7416
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define INF 1<<29
#define LL long long
#define ek()(putchar('\n'))
#define sk()(putchar(' '))
#define WY()(putchar('Y'),putchar('e'),putchar('s'),ek())
#define WN()(putchar('N'),putchar('o'),ek())
#define MAXN 15
#define MAXSTATE 1<<15 
using namespace std;
inline int Read(){
	int X=0,flag=1;char ch=0;
	while (ch<'0'||ch>'9'){
		if (ch=='-') flag=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9')
	  X=(X<<3)+(X<<1)+ch-48,ch=getchar();
	return X*flag;
}
inline void Write(int x){
	if (x<0) x=-x,putchar('-');
	if (x>9) Write(x/10);
	putchar(x%10+48);
}
int n,m;
int dis[MAXN+1][MAXN+1];
int exc[MAXSTATE+5];
int p[MAXSTATE+5];
int DP[MAXSTATE+5][MAXN+1];
int lowbit(int x){
	return x&(-x);
}
int main(){
	n=Read(),m=Read();
	for (int i=0;i<n;i++)
	  exc[1<<i]=i;
	int sum=0;
	for (int i=1;i<=m;i++){
		int x=Read()-1,y=Read()-1;
		sum+=dis[x][y]=dis[y][x]=Read();
	} 
	for (int s=0;s<(1<<n);s++){
		int x=s;
		int tmp=lowbit(x);
		int now=exc[tmp];
		x-=tmp;
		p[s]=p[x];
		for (;x;x-=lowbit(x)){
			int y=exc[lowbit(x)];
			p[s]+=dis[now][y];
		}
	}
	for (int i=0;i<(1<<n);i++)
	  for (int j=0;j<n;j++)
	    DP[i][j]=-INF;
	DP[1][0]=0;
	int ans=0;
	for (int s=0;s<(1<<n);s++){
		for (int x=s;x;x-=lowbit(x)){
			int tmp=lowbit(x);
			for (int st=s;st;st=(st-1)&s)
			  if ((st&tmp)&&DP[(s-st)|tmp][exc[tmp]]!=-INF)
			  	DP[s][exc[tmp]]=max(DP[s][exc[tmp]],DP[(s-st)|tmp][exc[tmp]]+p[st]);   
			for (int j=1;j<=n;j++)
			  if (!(s&(1<<j))&&dis[exc[tmp]][j]&&DP[s][exc[tmp]]!=-INF)
			    DP[s|(1<<j)][j]=max(DP[s|(1<<j)][j],DP[s][exc[tmp]]+dis[exc[tmp]][j]);
		}
		if ((s&(1<<n-1))&&DP[s][n-1]!=-INF) ans=max(ans,DP[s][n-1]); 
	}  
	
	Write(sum-ans);ek();
	return 0;
}

Measured memory_bytes: 8576
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	
	ll n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			int tmp = GCD(i, j);
			for (int k = 1; k <= n; k++) {

				sum += GCD(tmp, k);
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a = 0;
	int b = 0;
	cin >> a;
	cin >> b;
	if (a == b)
	{
		cout << "a == b" << endl;
	}
	if (a > b)
	{
		cout << "a > b" << endl;
	}
	if (a < b)
	{
		cout << "a < b" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3004
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 0621
 *  2020/5/10
 */
public class Main {

    PrintStream log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    PrintStream result = System.out;
    Scanner sc = new Scanner(System.in);

    void main() throws IOException {

        int N = sc.nextInt();
        int M = sc.nextInt();
        sc.nextLine();

        String[] s = new String[N];
        for(int i = 0; i < N; i++) {
            s[i] = sc.nextLine();
        }
        
        int min  = Integer.MAX_VALUE;
        
        // WBR
        for(int WL = 1; WL < N - 1; WL++) {
            for(int BL = 1; BL < N - WL; BL++) {
                //log.printf("WL BL %d %d\n", WL, BL);
                int cnt = 0;
                for(int n = 0; n < N; n++) {
                    char c = 'R';
                    if (n < WL)
                        c = 'W';
                    else if (n < WL + BL) 
                        c = 'B';
                    for(int m = 0; m < s[n].length(); m++) {
                        if (s[n].charAt(m) != c) {
                            cnt++;
                        }
                    }
                }
                log.printf("WL BL %d %d cnt = %d\n", WL, BL, cnt);
                min = Math.min(cnt, min);
            }
        }
        result.println(min);
    }

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


}




Measured memory_bytes: 34272
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

void solve()
{
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y;
}
int main()
{
	fast;
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int isPrime(ll num){
    if(num<2){
        return false;
    }else if(num==2){
        return true;
    }else if(num%2==0){
        return false;
    }
    for(int i=3; i<=sqrt(num); i+=2){
        if(num%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    ll n;
    cin>>n;
    ll max;
    if(isPrime(n)){
        cout << n-1;
        return 0;
    }
    FOR(i,1,sqrt(n)+1){
        if(n%i==0){
            max=i;
        }
    }
    ll step;
    step = max-1+(n/max)-1;
    cout << step;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
char s[100001];
int cnt[100001]={};
int main(){
    int n,k;
    scanf("%d%d%s",&n,&k,s);
    int i=0,cnti=1;
    while(true){
        while(i<n&&s[i]=='0'){
            cnt[cnti]++;
            i++;
        }
        if(i==n)break;
        cnti++;
        while(i<n&&s[i]=='1'){
            cnt[cnti]++;
            i++;
        }
        if(i==n)break;
        cnti++;
    }
    for(i=1;i<=cnti;i++)cnt[i]+=cnt[i-1];
    int ans=cnt[std::min(2*k,cnti)];
    for(i=2;i<=cnti;i+=2){
        ans=std::max(ans,cnt[std::min(i+2*k,cnti)]-cnt[i-1]);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int NM = 100005;
int N, M, c[3], vis[NM], odd;
vector<int> e[NM]; 

void f(int x, int y) {
    if (vis[x]) {
        odd |= (vis[x] != y);
        return;
    }
    vis[x] = y;
    c[y]++;
    for (auto &i : e[x]) {
        f(i, 3 - y);
    }
    return;
}
void solve() {
    cin >> N >> M;
    for (int i = 0, x, y; i < M; i++) {
        cin >> x >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    odd = 0;
    f(1, 1);
    if (odd) {
        cout << 1LL * N * (N - 1) / 2 - M << endl;
    } else {
        cout << 1LL * c[1] * c[2] - M << endl;
    }
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

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

int main()
{
  string b;
  cin >> b;
  
  string ans;
  if (b == "A") ans = "T";
  else if (b == "T") ans = "A";
  else if (b == "C") ans = "G";
  else ans = "C";
  
  cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	cin >>s;
	sort(all(s));
	cout<<solve(s[0]==s[1] and s[2]==s[3] and s[1]!=s[2])<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  int a=x/1000,b=x/100-a*10,c=x/10-a*100-b*10,d=x%10;
  if(a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7;
  else if(a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7;
  else if(a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7;
  else if(a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7;
  else if(a+b-c-d==7)  cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7;
  else if(a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7;
  else if(a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7;
  else if(a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 102
#define MAXK 100005
using namespace std;
const int Mod = 1e9 + 7;

int n, K, a[N];
long long f[MAXK], g[MAXK], sumf[MAXK], sumg[MAXK];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n >> K;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);
    f[0] = 1;
    for (int i = 0; i <= K; ++i)
        sumf[i] = 1;
    for (int i = 1; i <= n; ++i) {
        swap(f, g), swap(sumf, sumg);
        sumf[0] = 0;
        for (int j = 0; j <= K; ++j) {
            f[j] = sumg[j] - (j - a[i] - 1 < 0 ? 0 : sumg[j - a[i] - 1]);
            sumf[j] = (sumf[j - 1] + f[j]) % Mod;
        }
    }
    cout << (f[K] % Mod + Mod) % Mod << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	string s;
	cin >> s;
	if(s[0]==s[1] && s[1]==s[2]){
		printf("No\n");
	}else{
		printf("Yes\n");
	}

	return 0;
}


Measured memory_bytes: 256
import sys

N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=sys.maxsize

for i in range(N):
  L[i+1]=L[i]+A[i]

for i in range(1,N):
  x = L[i]
  y = L[-1] - L[i]
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

Measured memory_bytes: 23800
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int K = in.nextInt();
        int[] A = new int[N];
        int pos = 0;
        for(int i=0;i<N;i++){
            A[i]=in.nextInt();
        }
        for(int i=0;i<N;i++){
            if(A[i]==1){
                pos = i;
                break;
            }
        }
        int ans = Integer.MAX_VALUE;
        for(int j=0;j<K;j++){
            int left = Math.max(0,pos-j); // 长度为left,最右端邻居是1
            int right = Math.max(0,(N-pos)-(K-j)); //长度为right
            int leftTimes = 0;
            if(left>0) leftTimes = (left-1)/(K-1)+1;
            int rightTimes = 0;
            if(right>0) rightTimes = (right-1)/(K-1)+1;
            ans = Math.min(ans,1+leftTimes+rightTimes);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 49944
n, x = map(int, input().split())
a = list(map(int, input().split()))

c = 0
for i in range(n-1):
	t = max(0, a[i] + a[i+1] - x)
	a[i+1] -= t
	if a[i+1] < 0:
		a[i] += a[i+1]
		a[i+1] = 0
	c += t
print(c)

Measured memory_bytes: 14060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

main(){
  int i,j,m,temp,sum;
  while(1){
    sum=0;
    cin >> m;
    if(m==0){
      break;
    }
    for(i=0;i<9;i++){
      cin >> temp;
      sum+=temp;
    }
    cout << m-sum << endl;
  }
}

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

string s;

int main(){
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[s.size()-i-1]) ans++; 
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i) 
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    int a[210];
    rep(i,n){
      cin >> a[i];
    }
    int ans = 0;
   while(1){
     bool odd = false;
     rep(i,n){
       if(a[i]%2==1){
         odd = true;}
       }
      if (odd) break;
     rep (i,n){
       a[i]/=2;
     }
     ans +=1;
     }
     cout << ans<< endl;
   }

Measured memory_bytes: 256
package main

import(
  "fmt"
)

func main(){
  var n,a,b int
  fmt.Scan(&n,&a,&b)
  var s string
  fmt.Scan(&s)

  pass := 0
  brank := 0
  for i := 0; i < len(s); i++ {
    if s[i] == 'a' && pass < a+b {
      pass++
      fmt.Println("Yes")
    } else if s[i] == 'b' && pass<a+b && brank < b {
      pass++
      brank++
      fmt.Println("Yes")
    } else {
      fmt.Println("No")
    }
  }
}


Measured memory_bytes: 3200