akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int a, b; std::cin >> a >> b;
  int k; std::cin >> k;
  int cnt = 0;
  ddrep(x, 100) {
    if (a % x == 0 && b % x == 0) cnt++;
    if (cnt == k) {
      std::cout << x << "\n";
      return 0;
    }
  }
}


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

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

  if ((a <= 0 && 0 <= b) || a == 0 || b == 0) {
    cout << "Zero" << endl;
    return 0;
  } else if (0 < a) {
    cout << "Positive" << endl;
    return 0;
  }

  if ((b-a) % 2 == 0) {
    cout << "Negative" << endl;
  } else {
    cout << "Positive" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        m: usize,
        mut a: [usize; n],
        bc: [(usize, usize); m],
    }
    let mut dicts = HashMap::new();
    for (b, c) in bc {
        *dicts.entry(c).or_insert(0) += b;
    }
    for a_ in a {
        *dicts.entry(a_).or_insert(0) += 1;
    }

    let mut v: Vec<_> = dicts.iter().collect();
    v.sort_by(|a, b| a.0.cmp(b.0).reverse());


    let mut cnt = 0;
    let mut ans = 0;
    for (k_, v_ ) in v {
        let v__ = min(*v_, &n-&cnt);
        ans += v__ * k_;
        cnt += v__;
        if cnt == n {
            break
        }
    }
    println!("{}", ans);
}


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

int blood[4];

int main(void){
  int a;
  string b;
  while(cin >> a >> b){
    if(b[1] == 'A' && b[2] == 'B') blood[2]++;
    else if(b[1] == 'A') blood[0]++;
    else if(b[1] == 'B') blood[1]++;
    else if(b[1] == 'O') blood[3]++;
  }

  for(int i = 0; i < 4; i++){
    cout << blood[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <vector>
#include <deque>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

void read_problem(int& n, vector<int>& a)
{
    scanf("%d\n", &n);

    a.resize(n);
    REP(i, n) {
        scanf("%d", &a[i]);
    }
}

int main()
{
    int n;
    vector<int> a;
    read_problem(n, a);

    deque<int> b;
    b.push_back(a[0]);
    bool left = n % 2 == 0;
    FOR(i, 1, n) {
        if(left)
            b.push_front(a[i]);
        else
            b.push_back(a[i]);
        left ^= 1;
    }

    REP(i, n) {
        printf("%d%c", b[i], i == n-1 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 3712
N, K, Q = (int(x) for x in input().split())
A = [int(input()) for i in range(Q)]
ans = [K-Q for i in range(N)]

for a in A:
    ans[a-1] += 1

for b in ans:
    if b > 0:
        print("Yes")
    else:
        print("No")


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

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

  int ans;
  if (a == b) ans = a * 2;
  else ans = max(a, b) * 2 - 1;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;

signed main(){
    
    int a[3];
    for(int i = 0; i < 3; i++) cin >> a[i];
    int ma = 0;
    int mi = 20202;
    for(int i = 0; i < 3; i++){
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    
    }

    cout << ma - mi << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int x;
double p;

int main(void)
{
	cin >> x >> p;
	p /= 100;
	
	double ans;
	if(x % 2 == 0){
		ans = x/2/p;
	}
	else{
		ans = p*(x-1)/2/p + (1-p)*(x+1)/2/p + 1;
	}
	printf("%.11f\n", ans);
	return 0;
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int> 
#define piii pair<pair<int,int>,int> 

#define chalne_de continue
int mod=1000000007;
const int N = 1000005;

ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	string s;
	cin >> s;
	int a[27] = {0};
	int l = s.length();
	for ( int i = 0; i < l; i++)
	{
		a[s[i]-'a']++;
	}
	for ( int i = 0; i < 26; i++)
	{
		if ( a[i] > 1)
		{
			cout << "no";
			return 0;
		}
	}
	cout << "yes";
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
O = str(input())
E = str(input())
a = []
if len(O) == len(E):
  for i in range(len(O)):
    a.append(O[i]+E[i])
else:
  for i in range(len(O)-1):
    a.append(O[i]+E[i])
  a.append(O[-1])
L = "".join(a)
print(L)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	LL ans = 0;
	int N;
	cin >> N;
	vector<int> line(N-1);
	foreach(i, line)cin>>i;
	ans += line.front() + line.back();
	REP(i, N-2){
		ans += min(line[i], line[i+1]);
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main()
{
    int R, ABC=1200, ARC=2800;
    string ans;

    cin >> R;
    if (R < ABC) ans = "ABC";
    else if (R < ARC) ans = "ARC";
    else ans = "AGC";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define int long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <=n; i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
#define PI = atan(1.0) * 4.0;
#define MOD = 1e9 + 7;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
    start();
    int n;
    cin >> n;
    string ans = "";
    while (n > 0) {
        n--;
        char ch = 'a' + n % 26;
        n /= 26;
        ans += ch;
    }
    reverse(all(ans));
    cout << ans;
    return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[10][10];
int main(){
    int n;
    cin>>n;
    ll ans=0;
   for(int i=1;i<=n;i++){
       int t=i;
       ll f=t%10;
       while(t>=10){
            t/=10;
       }
       dp[f][t]++;
   }
   for(int i=1;i<10;i++){
       for(int j=i;j<10;j++){
           if(i==j)ans+=dp[i][i]*dp[i][i];
           else ans+=dp[i][j]*dp[j][i]*2;
          //if(dp[i][j]) cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<dp[j][i]<<endl;
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
char str[1000005];
int Q;
long long getans(int nk)
{
	long long sum1=0,sum2=0,sum3=0;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(i>nk)
		{	
			if(str[i-nk]=='D')
			{
				sum1--;
				sum3-=sum2;
			}	
			if(str[i-nk]=='M')
			{
				sum2--;
			}
		}

		if(str[i]=='D')sum1++;
		if(str[i]=='M')sum2++,sum3+=sum1;
		if(str[i]=='C')ans+=sum3;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",str);
	for(int i=n;i>=1;i--)str[i]=str[i-1];
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++)
	{
		int nk;
		scanf("%d",&nk);
		printf("%lld\n",getans(nk));
	}
	return 0;
}


Measured memory_bytes: 1280
import sys
from itertools import product
def input(): return sys.stdin.readline().rstrip()

def main():
    N, A, B, C = map(int, input().split())
    l = [int(input()) for _ in range(N)]

    ans = 10 ** 7
    for l_li in product(range(4), repeat = N):
        cost = -30
        a = 0
        b = 0
        c = 0
        for i, li in enumerate(l_li):
            if li > 0:
                cost += 10
                if li == 1:
                    a += l[i]
                elif li == 2:
                    b += l[i]
                elif li == 3:
                    c += l[i]
        cost += abs(A - a) + abs(B - b) + abs(C - c)
        if a * b * c > 0 and ans > cost:
            ans = cost
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
A,B,K = map(int,input().split(" "))
if A+B < K:print(0,0)
elif A > K:print(A-K,B)
elif A  <= K:print(0,A+B-K)
# Kenparさん、写経させていただきました。ありがとうございます。
# こんな解法があったなんて・・・ 

Measured memory_bytes: 2940
open Batteries
let explode s = List.init (String.length s) (String.get s)
let s = (explode (read_line ()))

let all = explode "qwertyuiopasdfghjklzxcvbnm"
let rec ans lst =
  match lst with
   [] -> []
  | first :: rest -> if List.exists (fun p -> p = first) s then ans rest else first :: ans rest

let a = List.sort compare (ans all)
let _ = 
  match a with
  | [] -> print_endline "None"
  | first :: rest -> print_char first; print_string "\n"


Measured memory_bytes: 6656
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] A = new int[N];
   for(int i=0;i<N;i++ )
   {
     A[i]  = sc.nextInt();
   }
   int[] B = new int[N];
   for(int i=0;i<N;i++ )
   {
     B[i]  = sc.nextInt();
   }
      int[] C = new int[N-1];
   for(int i=0;i<N-1;i++ )
   {
     C[i]  = sc.nextInt();
   }
   int count=0;
   int total = 0;
   for(int i = 0; i<N ; i++)
   {

     if(i>=1 && A[i-1] +1 == A[i])
     {
      total = total+ B[A[i]-1] +C[A[i] -2];
      
     }
     else
     {
      total += B[A[i]-1];
       
     }  

   }
   
System.out.println(total);   
   
 }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int h,w;
  cin>>h>>w;
  char a[h][w];
  rep(i,h) {
    rep(j,w) cin>>a[i][j];
  }
  bool fh[h];
  bool fw[w];
  rep(i,h) fh[i] = false;
  rep(i,w) fw[i] = false;
  rep(i,h) {
    bool flag = true;
    rep(j,w) {
      if(a[i][j] == '#') flag = false;
    }
    if(flag) fh[i] = true;
  }
  rep(j,w) {
    bool flag = true;
    rep(i,h) {
      if(a[i][j] == '#') flag = false;
    }
    if(flag) fw[j] = true;
  }
  rep(i,h) {
    if(fh[i]) continue;
    rep(j,w) {
      if(fw[j]) continue;
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}


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

int main(){
  int N;
  string S;
  int i;
  
  cin>>N;
  cin>>S;
  int a;
  a=N/2;
  if(N%2==1){
    cout<<"No"<<endl;
    return 0;
  }
  else{
    for(i==0;i<a;i++){
      if(S.at(i)==S.at(i+a)){
}
      else{
        cout<<"No"<<endl;
        return 0;
      }
}
    cout<<"Yes"<<endl;
}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main() {
	ll cnt=0, n, x; cin >> n;
	ll min = 1LL << 60;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		x = a[i];
		cnt = 0;
		while (x % 2 == 0)
		{
			cnt++;
			x /= 2;
		}
		if (min > cnt) min = cnt;
	}
	cout << min;
}

Measured memory_bytes: 256
s=list(input())
k=int(input())
#print(s)
#print(len(s))
#print(k)
for i in range(len(s)):
    if s[i] != '1' or i == len(s)-1:
        if k <= i:
            print(s[k-1])
        else :
            print(s[i])
        break

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

int main(){
    int l, a, b, c, d;
    scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
    printf("%d\n", min(l - --a/c - 1, l - --b/d - 1));
    return 0;
}

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

#define MOD 1000000007LL
ll dp[51][51][51][51];

vector<string> split(string s, string p) {
  vector<string> ret;
  ll h = 0;
  REP(i, 0, s.size() - p.size() + 1) if(s.substr(i, p.size()) == p) {
    ret.push_back(s.substr(h, i - h));
    h = i + p.size();
    i += (ll) p.size() - 1;
  }
  ret.push_back(s.substr(h, (ll) s.size() - h));
  return ret;
}

int main(void) {
  ll A, T, C, G, M;
  scanf("%lld %lld %lld %lld\n", &A, &T, &G, &C);
  scanf("%lld\n", &M);
  vector<string> S(M);
  REP(i, 0, M) getline(cin, S[i]);

  map<string, map<string, ll>> mp;

  for(ll m = M - 1; m >= 0; m--) {
    string name = split(S[m], ": ")[0];
    string body = split(S[m], ": ")[1];
    vector<string> items = split(body, " ");
    for(string s : items) {
      if(s[0] == '[') {
        string t = s.substr(1, s.length() - 2);
        sort(t.begin(), t.end());
        if(++mp[name][t] > A + T + C + G) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        for(auto p : mp[s]) {
          string t = p.first;
          ll d = p.second;
          if((mp[name][t] += d) > A + T + C + G) {
            cout << 0 << endl;
            return 0;
          }
        }
      }
    }
  }

  REP(a, 0, A + 1) REP(t, 0, T + 1) REP(c, 0, C + 1) REP(g, 0, G + 1) dp[a][t][c][g] = 0;
  dp[0][0][0][0] = 1;

  string name = split(S[0], ": ")[0];
  ll cnt = 0;
  for(auto p : mp[name]) cnt += p.second;
  if(cnt > A + T + C + G) {
    cout << 0 << endl;
    return 0;
  }
  ll q = 0;
  for(auto p : mp[name]) {
    string s = p.first;
    ll x = p.second;
    for(ll k = 0; k < x; k++) {
      REP(a, 0, A + 1) REP(t, 0, T + 1) REP(c, 0, C + 1) {
        ll g = q - a - t - c;
        if(0 <= g && g <= G) for(char ch : s) {
          if(ch == 'A' && a + 1 <= A) (dp[a + 1][t][c][g] += dp[a][t][c][g]) %= MOD;
          if(ch == 'T' && t + 1 <= T) (dp[a][t + 1][c][g] += dp[a][t][c][g]) %= MOD;
          if(ch == 'C' && c + 1 <= C) (dp[a][t][c + 1][g] += dp[a][t][c][g]) %= MOD;
          if(ch == 'G' && g + 1 <= G) (dp[a][t][c][g + 1] += dp[a][t][c][g]) %= MOD;
        }
      }
      q++;
    }
  }
  cout << dp[A][T][C][G] << endl;
}


Measured memory_bytes: 55304
#include<iostream>
#include<vector>
using namespace std;
int main(){
  
  int n,a,b;
  vector<int> vec;
  cin >> n;

  while(n--){

    cin >> a;
  
    if(a == 0){
      cin >> b;
      vec.push_back(b);
    }

    if(a == 1){
      cin >> b;
      cout << vec[b] << endl;
    }

    if(a == 2){
      vec.pop_back();
    }

  }

  return(0);
}



Measured memory_bytes: 3912
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

int main(){
    long long n, md = 1;
    cin >> n;
    vector<int> ans;
    if(!n) cout << 0;
    while(n){
        if(!(n % 2)){
            ans.push_back(1);
        }
        else{
            ans.push_back(0);
            n--;
        }
        n /= -2;
    }
    for(int i = ans.size() - 1; i >= 0; --i) cout << !ans[i];
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define fi first
#define se second
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = 3.141593; const double EPS = 1e-12;
const ll INF = 2e18;
const int INT_INF = 1e9;
typedef pair<double, double>Pd;
double dist(P& p1, P& p2) {
	return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}
double dist(Pd& p1, Pd& p2) {
	return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}

int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };
char A[60][60];
int H, W;
bool valid(int x, int y) {
	if (A[x][y] == '.')return true;
	REP(k, 4) {
		int nx = x + dx[k], ny = y + dy[k];
		if (nx < 0 || nx >= H || ny < 0 || ny >= W)continue;
		if (A[nx][ny] == '#')return true;
	}
	return false;
}
void solve() {
 cin >> H >> W;;
	REP(i, H)REP(j, W)cin >> A[i][j];
	REP(i, H) {
		REP(j, W) {
			if (!valid(i, j)) {
				print("No"); return;
			}
		}
	}
	print("Yes");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())

a, b, c, d = [0]*Q, [0]*Q, [0]*Q, [0]*Q

for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

L = [i for i in range(1, M+1)]

iterations = combinations_with_replacement(L, N)

max_score = 0
for v in iterations:
    score = 0
    for i in range(Q):
        if v[b[i]-1] -  v[a[i]-1] == c[i]:
            score += d[i]
    if score > max_score:
        max_score = score

print(max_score)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
typedef tuple<int,int,int,int>T;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX =510000;
int main(){
  	int N,K;
  	cin >>N>>K;
  	string S;
  	cin >>S;
  	int red=0,blue=0;
  	int mae=0,usi=0;
  	if(S[0]=='L'){mae=1;}	
  	if(S[N-1]=='R'){usi=1;}
  	rep(i,N-1){
    	if(S[i]=='R'&&S[i+1]=='L')red++;
    	if(S[i]=='L'&&S[i+1]=='R')blue++;
    }
  	int unhappy=0;
  	if(K<red){unhappy=2*(red-K)+mae+usi;}
  	else if(K==red){
    	if(mae==0&&usi==0){unhappy=1;}
    	else{unhappy=mae+usi;}
    }
    else{
     	unhappy=1;
    }	
  	cout<<N-unhappy;
  
}


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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << "[";
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, H, D;
ll fsum[1000001] = {1};
ll val[1000000];

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> H >> D;
    repp(i, 1, N+1) fsum[i] = fsum[i-1]*i%MOD;
    val[0] = fsum[N];
    repp(i, 2, N+1) fsum[i] = (fsum[i]+fsum[i-1])%MOD;

    ll csum = val[0];
    repp(i, 1, H) {
        val[i] = csum*fsum[N]%MOD;
        csum = (csum+val[i])%MOD;
        if (i >= D) csum = (csum-val[i-D]+MOD)%MOD;
    }

    csum = 0;
    for (int i = max(0, H-D); i < H; i++) csum = (csum+val[i])%MOD;

    cout << csum << endl;
}


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

struct TEdge
{
    int u, v, w;
} a[100005];
int n, m, k, c[100005], dsu[200005];
long long ans = 0;

inline bool operator<(const TEdge &a, const TEdge &b)
{
    return a.w < b.w;
}

int trace(int u)
{
    return (dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]));
}

bool unity(int u, int v)
{
    if ((u = trace(u)) == (v = trace(v)))
        return false;
    if (dsu[u] > dsu[v])
        swap(u, v);
    dsu[u] += dsu[v];
    dsu[v] = u;
    return true;
}

int main()
{
    memset(dsu, -1, sizeof(dsu));
    scanf("%d%d%d", &n, &m, &k);
    --k;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", c + i);
        if (c[i] == 0)
            c[i] = n + i;
    }
    for (int i = 1; i <= m; i++)
        scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w);
    sort(a + 1, a + m + 1);
    for (int i = 1; k && i <= m; i++)
        if (unity(c[a[i].u], c[a[i].v]))
        {
            ans += a[i].w;
            --k;
        }
    printf("%lld", k ? -1 : ans);
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    ll n,k; cin>>n>>k;
    vl A(n);
    rep(i,n) cin >> A[i];
    sort(all(A));

    auto check = [&](ll x){
        ll cnt = 0ll;
        rep(i,n){
            if(A[i] < 0){
                int l=-1, r=n;
                while(r-l>1){
                    int m = (l+r)/2;
                    if(A[m]*A[i]<x) r = m; else l = m;
                }
                cnt += n-r;
            }else{
                int l=-1, r=n;
                while(r-l>1){
                    int m = (l+r)/2;
                    if(A[m]*A[i]<x) l = m; else r = m;
                }
                cnt += r;
            }
            if(A[i]*A[i] < x) cnt--;
        }
        return cnt < 2*k;
    };

    ll MX = ll(1e18) + 1;
    ll l = -MX, r = MX;
    while(r-l>1){
        ll m = (l+r) / 2;
        if(check(m)) l = m;
        else r = m;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

string func(int n){
  string res = "1";
  rep(i,n-2)res+="0";
  res+="1";
  return res;
}

int main(){
  int n = in();
  if(n==1){
    cout << 1 << endl;
    cout << "1" << endl;
    return 0;
  }
  if(n==2){
    cout << 2 << endl;
    cout << "11" << endl;
    cout << "0" << endl;
    return 0;
  }
  cout << n-1 << endl;
  rep(i,2,n+1){
    cout << func(i) << endl;
  }

  return 0;
}



Measured memory_bytes: 3280
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split();
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);
        Console.WriteLine(Math.Max(0,B + C - A));
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

template<class T>
inline void read(T& x) {
  T s = 0, base = 1;
  char c;
  while (!isdigit(c=getchar())) if (c == '-') base = -base;
  while (isdigit(c)) {
    s = s * 10 + (c^48);
    c = getchar();
  }
  x = base * s;
}

int main() {
  int N;
  read(N);

  int donuts;
  if (N % 2 == 1) donuts = 1;
  else donuts = 0;
  
  while (donuts * 7 <= N) {
    int remain = N - donuts * 7;
    if (remain % 4 == 0) {
      printf("Yes\n");
      return 0;
    }
    donuts += 2;
  }

  printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

ll dp[12][2][2][2][2][2]; // dp[i][j][k][r][l][z]...i:桁数, j:未満フラグ, k:7を使ったか, r:5を使ったか, l:3を使ったか, z:0以外の値を使ったか

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0][0][0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        int t = s[i] - '0';
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                for (int r = 0; r < 2; r++) {
                    for (int l = 0; l < 2; l++) {
                        for (int z = 0; z < 2; z++) {
                            for (int m = 0; m <= (j ? 9 : t); m++) {
                                if (z == 0) {
                                    if (m != 0 && m != 3 && m != 5 && m != 7) continue;
                                } else if (m != 3 && m != 5 && m != 7) continue;
                                dp[i + 1][j || m < t][k || m == 7][r || m == 5][l || m == 3][z || m] += dp[i][j][k][r][l][z];
                            }
                        }
                    }
                }
            }
        }
    }
    ll ans = dp[n][0][1][1][1][1] + dp[n][1][1][1][1][1];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007

int main(void) {
	int i,n;
	long long p = 1LL;
	
	scanf("%d",&n);
	
	for (i = 1;i <= n;i++) {
		p *= i;
		p %= MOD;
	}
	
	printf("%lld\n",p);
	
	return 0;
}


Measured memory_bytes: 128
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

def TS(n):
	return n*(n+1)//2

s = input()
l = []
t = [0,0]
b = s[0]
if b=="<":
	a = 0
else:
	a = 1

i=0
while 1:
	if i>len(s)-1:
		l.append(t)
		break
	else:
		if b==s[i]:
			t[a]+=1
			i+=1
		elif s[i]==">":
			a=1
			b = ">"
		else:
			b = "<"
			a=0
			l.append(t)
			t = [0,0]

#print(l)

ans = 0

for i in l:
	ans += TS(i[0]-1)
	ans += TS(i[1]-1)
	ans += max(i)

print(ans)

Measured memory_bytes: 20852
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ul = uint32_t;
using ull = uint64_t;
using namespace std;

int main() {
    fastIO;

    int n, k, d;
    cin >> n >> k;

    vector<bool> ate(101);
    for (int i = 1; i <= k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            ate[a] = true;
        }
    }

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

Measured memory_bytes: 3608
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N, M = 256;
  while(cin>>N,N){
	VI in(N);
	REP(i,N) cin >> in[i];

	int S = 100, A = 100, C = 100;
	double E = -1;
	REP(s,16) REP(a,16) REP(c,16){
	  int r = s;
	  VI out;
	  REP(i,N){
		r = (a*r + c)%M;
		out.PB((in[i] + r) % M);
	  }
	  double en = 0;
	  vector<bool> used(256, false);
	  REP(i,N){
		if(used[out[i]]) continue;
		used[out[i]] = true;
		int cnt = count(ALL(out), out[i]);
		en -= cnt * 1. / N * log2(cnt*1. / N);
	  }
	  if(en < E || E < 0){
		E = en;
		S = s, A = a, C = c;
	  }
	}

	cout << S << " " << A << " " << C << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1252
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 805;
int n, m, k;
char c[maxN][maxN];
int dist[maxN][maxN];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m >> k;
    int a = -1;
    int b = -1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> c[i][j];
            if (c[i][j] == 'S') {
                a = i;
                b = j;
            }
        }
    }
    memset(dist, -1, sizeof dist);
    queue < pair < int, int > > q;
    q.push({a, b});
    dist[a][b] = 0;
    while (!q.empty()) {
        auto it = q.front();
        q.pop();
        int x = it.first;
        int y = it.second;
        for (int k = 0; k < 4; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
            if (c[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                q.push({nx, ny});
            }
        }
    }
    int best = 2e9;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (dist[i][j] <= k && dist[i][j] != -1) {
                best = min(best, 1 + (min({i - 1, n - i, j - 1, m - j}) + k - 1) / k);
            }
        }
    }
    cout << best;
    return 0;
}

Measured memory_bytes: 3456
N = input()
x = list(map(int, input().split()))
end = True
count = 0

def div2(y):
    return y / 2

while end:
    for i in x:
        if i % 2 == 1:
            end = False
            break
    else:
        count += 1
        x = list(map(div2, x))
        continue
    break
print(count)

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

int main(){
  string S;
  cin >> S;
  
  char ans = 'A';
  
  
  if (S[0]=='A') ans='T';
  else if (S[0]=='T') ans='A';
  else if (S[0]=='G') ans='C';
  else if (S[0]=='C') ans='G';
  
  cout << ans << endl;
}


Measured memory_bytes: 256
use std::collections::BinaryHeap;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut queue: Vec<i64> = vec![];
    for _ in 0..n {
        queue.push(read());
    }
    let mut ans = 0;
    for l in 0..(std::cmp::min(n, k) + 1) {
        for r in 0..(std::cmp::min(n, k) - l + 1) {
            let mut now = 0;
            let mut hands: BinaryHeap<i64> = BinaryHeap::new();
            for i in 0..l {
                now += queue[i];
                hands.push(-queue[i]);
            }
            for j in 0..r {
                now += queue[n - j - 1];
                hands.push(-queue[n - j - 1]);
            }
            for _ in 0..k - (r + l) {
                let minus_value = match hands.pop() {
                    Some(i) => i,
                    None => break,
                };
                if minus_value < 0 {
                    break;
                }
                // negate value
                now += minus_value;
            }
            ans = std::cmp::max(ans, now);
        }
    }
    println!("{}", ans);
}


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

int main(void)
{
    long long N, M, K;
    cin >> N >> M >> K;
    vector<long long> a(N);
    vector<long long> b(M);
    for (long long i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (long long i = 0; i < M; i++)
    {
        cin >> b[i];
    }

    long long num = 0;
    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        if (num + a[i] > K)
        {
            break;
        }
        ans++;
        num += a[i];
    }
    long long anum = num;
    long long aans = ans;
    long long bans = 0;

    for (long long i = 0; i < M; i++)
    {
        if (num + b[i] > K)
        {
            break;
        }
        if (i == M-1)
                {
                    ans = ans + 1;
                    cout << ans << endl;
                    exit(0);
                }
        ans++;
        num += b[i];
    }
    anum = num;
    bans = ans - aans;

    for (long long i = aans-1; i > -1; i--)
    {
        anum -= a[i];
        num = anum;
        for (long long j = bans; j < M; j++)
        {
            if (num + b[j] > K)
            {
                if (j + i >= ans)
                {
                    ans = j + i;
                }
                anum = num;
                bans = j;
                break;    
            }
            if (j == M-1)
                {
                    if (j + i + 1> ans)
                    {
                        ans = j + i + 1;
                    }
                    cout << ans << endl;
                    exit(0);
                }
            num += b[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6724
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        for (int i = L; i <= R; i++) {
            count += i % d == 0 ? 1 : 0;
        }
        System.out.println(count);
    }
}

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

using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();

    int i,ans=0;

    for(i=0;i<n;i++)
    {
    if(s[i]!=s[n-i-1]) ans++;

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


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

int main()
{
    map<int, int> mp1;
    map<int, int> mp2;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        if(i % 2 == 0)
        {
            int a;
            cin >> a;
            mp1[a]++;
        }
        else
        {
            int a;
            cin >> a;
            mp2[a]++;
        }
    }
    //一巡目
    int max1 = 0;
    int idx = 0;
    for(pair<int, int> m: mp1)
    {
        if(m.second > max1)
        {
            max1 = m.second;
            idx = m.first;
        }
    }
    int max2 = 0;
    for(pair<int, int> m: mp2)
    {
        if(m.second > max2 && m.first != idx) max2 = m.second;
    }
    int ans1 = (N/2 - max1) + (N/2 - max2);
    //二巡目
    max1 = 0;
    idx = 0;
    for(pair<int, int> m: mp2)
    {
        if(m.second > max1)
        {
            max1 = m.second;
            idx = m.first;
        }
    }
    max2 = 0;
    for(pair<int, int> m: mp1)
    {
        if(m.second > max2 && m.first != idx) max2 = m.second;
    }
    int ans2 = (N/2 - max1) + (N/2 - max2);
    int ans = min(ans1, ans2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <array>
#include <iostream>
#include <map>
#include <vector>

template <typename Map, typename Value = typename Map::mapped_type>
Value &
MapIncrementCount(Map &map, typename Map::key_type key, Value value)
{
    auto [it, flag] = map.try_emplace(key, 0);
    (void)flag;
    auto &v = it->second;
    v += value;
    return v;
}

int
main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::size_t n;
    std::cin >> n;
    std::vector<int> inputs;
    inputs.reserve(n);
    for (std::size_t i = 0; i<n; ++i)
    {
        int input;
        std::cin >> input;
        inputs.emplace_back(input);
    }

    std::size_t operationCount;
    std::cin >> operationCount;
    std::vector<std::pair<int, int>> operations;
    operations.reserve(operationCount);
    for (std::size_t i = 0; i<operationCount; ++i)
    {
        int b, c;
        std::cin >> b >> c;
        operations.emplace_back(b, c);
    }

    long long sum = 0;
    std::map<int, int> valueCounts;
    for (auto &input : inputs)
    {
        MapIncrementCount(valueCounts, input, 1);
        sum += input;
    }

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        auto &[b, c] = operations[i];

        auto findB = valueCounts.find(b);
        if (findB==valueCounts.end())
        {
            std::cout << sum << "\n";
            continue;
        }

        sum -= static_cast<long long>(b)*findB->second;
        sum += static_cast<long long>(c)*findB->second;

        MapIncrementCount(valueCounts, c, findB->second);
        valueCounts.erase(b);
        std::cout << sum << "\n";
    }
}


Measured memory_bytes: 7392