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

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

const int MX_K = 1e5+5;

int K, A[MX_K];

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

    cin >> K;
    FOR(i,1,K) cin >> A[i];

    array<long long,2> N = { 2,2 };
    bool rip = 0;
    RFOR(i,K,1){
        array<long long,2> x = { (N[0]+A[i]-1)/A[i] * A[i], N[1]/A[i] * A[i] };
        if (x[0] <= N[1]) N = x, N[1] += A[i]-1;
        else rip = 1;
    }
    if (rip) cout << -1;
    else cout << N[0] << ' ' << N[1];
}


Measured memory_bytes: 640
import java.math.BigDecimal;

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.nextLine();
		for(int i = 0 ; i < Integer.parseInt(n) ; i++){
			String x = sc.nextLine();
			String y = sc.nextLine();
			BigDecimal a = new BigDecimal(x);
			BigDecimal b = new BigDecimal(y);
			String str = a.add(b).toString();
			if(str.length() <= 80){
				System.out.println(str);
			} else {
				System.out.println("overflow");
			}
		}
		sc.close();
	}

}

Measured memory_bytes: 18468
//#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int maxn=1e6+100;
const int N=5e5+100;
const int M=2e6+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll f[N];
ll inv[N],Inv[N];
void CalFact()
{
    f[0]=1;
    for(int i=1;i<N;++i) f[i]=(f[i-1]*i)%mod;
    inv[N-1]=qpow(f[N-1],mod-2,mod);
    for(int i=N-2;~i;--i) inv[i]=inv[i+1]*(i+1)%mod;
    Inv[1]=1;
    for(int i=2;i<N;++i) Inv[i]=Inv[mod%i]*(mod-mod/i)%mod;
}
ll Com(int n,int m)
{
    return f[n]*inv[m]%mod*inv[n-m]%mod;
}
ll A(int n,int m)
{
    return f[n]*inv[n-m]%mod;
}
int main()
{
#ifdef local
      freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    IOS;cout.tie(0);
    CalFact();
    int n,m;cin>>n>>m;
    ll sum=0;
    for(int i=0;i<=n;++i)
    {
        if(i&1) sum=(sum-Com(n,i)*A(m-i,n-i)%mod+mod)%mod;
        else sum=(sum+Com(n,i)*A(m-i,n-i)%mod)%mod;
    }
    cout<<sum*A(m,n)%mod<<endl;
    return 0;
}


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

const int MOD = 1000000007;
ll dp[100005][2];

int main() {
    string L;
    cin >> L;
    int n = L.size();
    dp[0][0] = 1;
    rep(i, n) {
        if (L[i] == '1') {
            dp[i+1][0] = dp[i][0] * 2 % MOD;
            dp[i+1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD;
        } else {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1] * 3 % MOD;
        }
    }
    ll ans = dp[n][0] + dp[n][1];
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll T, X;
    cin >> T >> X;
    cout << fixed << setprecision(3) << (ld)T / X << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int t = 0;
  for (char c : s) {
    t += (c - '0');
  }
  
  t %= 9;
  if (t == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
    ll n,temp;
    cin>>n;
    ll a[n+1]={0};
    for(int i=2;i<=n;i++)
    {
        cin>>temp;
        a[temp]++;
    }
    for(int i=1;i<=n;i++) cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 5156
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N;
    cin >> N;

    int odd_time = 0;

    for(int i = 1 ; i <= N ; i++){
        if( i%2 != 0 ) odd_time++;
    }

    cout << fixed << setprecision(10) << (double) odd_time/N << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct Graph {
  graph: Vec<Vec<usize>>,
  v: usize,
}

type Edge = (usize, usize);
impl Graph {
  pub fn new(edges: &[Edge], v: usize) -> Self {
    let mut graph = vec![Vec::new(); v];
    for &(u, v) in edges {
      graph[u].push(v);
      graph[v].push(u);
    }
    Self { graph, v }
  }

  pub fn solve(&self, start: usize) -> Vec<Option<usize>> {
    let mut visited = std::collections::HashSet::new();
    let mut parent_list = vec![None; self.v];
    let mut que = std::collections::VecDeque::new();
    visited.insert(start);
    que.push_back(start);
    while let Some(u) = que.pop_front() {
      for &v in &self.graph[u] {
        if visited.contains(&v) {
          continue;
        }
        visited.insert(v);
        parent_list[v] = Some(u);
        que.push_back(v);
      }
    }
    parent_list
  }
}

fn main() {
  input! {
    n: usize, m: usize,
    edges: [(Usize1, Usize1); m]
  };

  let graph = Graph::new(&edges, n);
  let res = graph.solve(0);
  println!("Yes");
  for i in 1..n {
    println!("{}", res[i].unwrap() + 1);
  }
}


Measured memory_bytes: 19884
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int a[MAX_N];
int n,m;
vector<int> G[MAX_N];
int color[MAX_N];
deque<int> L;
bool flag;	//????????????

void visit(int u)
{
	if(color[u] == 0){
		flag = true;	//DAG??§??????
		return;
	}
	if(color[u] == 1){
		return;
	}
	color[u] = 0;
	for(int i=0;i<G[u].size();i++){
		visit(G[u][i]);
	}
	color[u] = 1;
	L.push_front(u);
}

int main()
{
	scanf("%d%d",&n,&m);
	rep(i,m){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u-1].push_back(v-1);
	}
	rep(i,n){
		color[i] = -1;
	}
	rep(i,n){
		if(color[i] == -1){
			flag = false;
			visit(i);
		}
		if(flag){
			break;
		}
	}
	rep(i,n){
		printf("%d\n",L[i]+1);
	}
	flag = false;
	rep(i,n-1){
		if(find(G[L[i]].begin(),G[L[i]].end(),L[i+1]) == G[L[i]].end()){
			flag = true;
			break;
		}
	}
	if(flag){
		printf("1\n");
	}else{
		printf("0\n");
	}
}

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

m = [list() for _ in range(N + 1)]
for _ in range(M):
    A, B = list(map(int, input().split()))
    m[A].append(B)
    m[B].append(A)

visited = [N + 100 for _ in range(N + 1)]
step = 0
visited[1] = step
que = [1]

os = [0 for _ in range(N + 1)]

while len(que) > 0:
    step += 1

    q = que.pop(0)

    for t in m[q]:
        if visited[t] == N + 100:
            que.append(t)
        if step <= visited[t]:
            visited[t] = step
            os[t] = q 

for o in os[2:]:
    if o == 0:
        print('No')
        break
else:
    print('Yes')
    for _o in os[2:]:
        print(_o)


Measured memory_bytes: 37744
#include<stdio.h>
#include<string.h>

int main(){
    char *s1 = "SUN";
    char *s2 = "MON";
    char *s3 = "TUE";
    char *s4 = "WED";
    char *s5 = "THU";
    char *s6 = "FRI";
    char *s7 = "SAT";
    
    char s[3];
    scanf("%s",&s);
    if(strcmp(s,s1)==0){
        printf("7");
    }
    else if(strcmp(s,s2)==0){
        printf("6");
    }
        else if(strcmp(s,s3)==0){
        printf("5");
    }
    else if(strcmp(s,s4)==0){
        printf("4");
    }
    else if(strcmp(s,s5)==0){
        printf("3");
    }
    else if(strcmp(s,s6)==0){
        printf("2");
    }
    else if(strcmp(s,s7)==0){
        printf("1");
    }

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int q,x,i,k,l[N],r[N],j,n,a[N],b[N],f[N];
long long ans;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d %d",&a[i],&b[i]);
		f[i]=a[i]==b[i];
	}
	for(i=1;i<=n;++i)
		if(f[i]&&f[i+1]&&f[i+2])
		{
			puts("Yes");
			return 0;
		}
	puts("No");
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << ' ';
        }
        s << vec[i];
    }
    return s << endl;
}

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    auto A = make_vec<int>(H, W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    int Q;
    cin >> Q;
    vector<int> L(Q), R(Q);
    for (int i = 0; i < Q; i++) {
        cin >> L.at(i) >> R.at(i);
    }

    using P = pair<int, int>;
    vector<vector<P>> Cor = make_vec<P>(D, H * W / D + 2);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            Cor[A[i][j] % D][A[i][j] / D] = make_pair(i, j);
        }
    }

    vector<vector<int>> S;
    for (auto C : Cor) {
        vector<int> sum((int)C.size());
        for (int i = 0; i < (int)C.size() - 1; i++) {
            P p1 = C[i];
            P p2 = C[i + 1];
            sum[i + 1] += sum[i] + abs(p2.first - p1.first) + abs(p2.second - p1.second);
        }
        S.push_back(sum);
    }

    /*
    for (int i = 0; i < D; i++) {
        cerr << S[i];
    }
*/
    for (int i = 0; i < Q; i++) {
        int d = L[i] % D;
        cout << S[d][R[i] / D] - S[d][L[i] / D] << "\n";
    }
}


Measured memory_bytes: 12212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	map<char,int> mp;
	rep(i,0,n){
		string s; cin>>s;
		mp[s[0]]++;
	}
	vector<char> vec={'M','A','R','C','H'};
	vi c={0,0,1,1,1};
	ll ans=0;
	do{
		ll cnt=1;
		rep(i,0,5){
			if(c[i]==0) continue;
			cnt*=mp[vec[i]];
		}
		ans+=cnt;
	}while(next_permutation(all(c)));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <cmath>
using namespace std;

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

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

    unordered_set<int> app;
    for(int i=0; i<4 && i<n; i++){
        for(int j=0; j<n-i; j++){
            int num=0;
            for(int k=0; k<=i; k++){
                num+=seq[j+k]*pow(10,i-k);
            }
            app.insert(num);
        }
    }

    for(int i=0; i<10000; i++){
        if(app.count(i)==0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3356
import itertools
def f(s):
 for a,b,c,d in itertools.permutations(s):
  for x,y,z in itertools.product('+-*',repeat=3):
   for t in[f"({a} {x} {b}) {y} ({c} {z} {d})",f"(({a} {x} {b}) {y} {c}) {z} {d}",f"{a} {x} ({b} {y} ({c} {z} {d}))",f"({a} {x} ({b} {y} {c})) {z} {d}",f"{a} {x} (({b} {y} {c}) {z} {d})"]:
    if eval(t)==10:return'('+t+')'
 else:return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))


Measured memory_bytes: 5680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int min=Math.max(a, c);
		int max=Math.min(b, d);
		if(max-min<0)System.out.println(0);
		else System.out.println(max-min);
		
	}

}


Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  if(A % K == 0 || B % K == 0) cout << "OK" << endl;
  else if(B / K > A / K) cout << "OK" << endl;
  else cout << "NG" << endl;
}

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

typedef long long LL;

const int N=100000;

int n,h,w;
struct card{
  int x,y,v;
}a[N+9];

bool cmp(const card &a,const card &b){return a.v>b.v;}

void into(){
  scanf("%d%d%d",&n,&h,&w);
  for (int i=1;i<=n;++i)
	scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].v);
}

int uni[N*2+9],siz[N*2+9],cnt[N*2+9];

int Query_uni(int k){return k==uni[k]?k:uni[k]=Query_uni(uni[k]);}

LL ans;

void Get_ans(){
  sort(a+1,a+n+1,cmp);
  for (int i=1;i<=h+w;++i) uni[i]=i,siz[i]=1,cnt[i]=0;
  for (int i=1;i<=n;++i){
	int fx=Query_uni(a[i].x),fy=Query_uni(a[i].y+h);
	if (fx==fy){
	  if (cnt[fx]>=siz[fx]) continue;
	  ++cnt[fx];ans+=a[i].v;
	}else{
	  if (cnt[fx]+cnt[fy]>=siz[fx]+siz[fy]) continue;
	  uni[fy]=fx;siz[fx]+=siz[fy];cnt[fx]+=cnt[fy]+1;
	  ans+=a[i].v;
	}
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
struct dice{
    int u, d, f, b, l, r;
    dice(int up,int down,int front, int back, int left, int right){
        u = up, d = down, f = front, b = back, l = left, r = right;
    }
    void goup(){    int tmp = u; u = b, b = d, d = f, f = tmp; }
    void godown(){  int tmp = u; u = f, f = d, d = b, b = tmp; }
    void goleft(){  int tmp = u; u = r, r = d, d = l, l = tmp; }
    void goright(){ int tmp = u; u = l, l = d, d = r, r = tmp; }
};
int main() {
    init();
    ll u, b, r, l, f, d;
    cin >> u >> b >> r >> l >> f >> d;
    dice dice(u, d, f, b, l, r);

    string s;
    cin >> s;
    rep(i,s.size()){
        if (s[i] == 'N')
            dice.goup();
        else if(s[i]=='S')
            dice.godown();
        else if(s[i]=='W')
            dice.goleft();
        else
            dice.goright();
    }

    cout << dice.u << endl;
}


Measured memory_bytes: 3220
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
class SegmentTree:
    def segfunc(self,x,y):
        #ここに評価
        po = [0 for i in range(26)]
        for i in range(26):
            po[i] = x[i]+y[i]
        return po

    #nは総数、initがlist,ide_eleが元
    def __init__(self,n,init,ide_ele):
        self.n = n
        self.ide_ele = ide_ele
        self.num = 2**(n-1).bit_length()
        self.seg = [ide_ele for i in range(2*self.num)]
        for i in range(n):
            self.seg[i+self.num-1] = init[i]
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
    
    
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])
    
    def query(self,p,q):
        if q <= p:
            return [1 if i == 0 else 0 for i in range(26)]
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p > 1:
            if p & 1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p //= 2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

def solver():
    n = onem()
    s = input().split()[0]
    po = onem()

    abc = [[0 for i in range(26)] for j in range(n)]

    for i in range(n):
        ppp = s[i]
        abc[i][ord(s[i]) - 97] += 1

    Se = SegmentTree(n,abc,[0 for i in range(26)])



    for i in range(po):
        a,b,c = input().split()
        a = int(a)
        b = int(b)
        if a == 1:
            ppp = [0] * 26
            ppp[ord(c) - 97] = 1
            Se.update(b-1,ppp)      
        else:
            c = int(c)
            op = Se.query(b-1,c)
            co = 0
            for i in range(26):
                if op[i] >= 1:
                    co += 1
            print(co)


if __name__ == "__main__":
    solver()



Measured memory_bytes: 459908
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

inline void InitRand()
{
    srand((unsigned int)time(NULL));
}

int main() {
    InitRand();
    int D; cin >> D;
    veci C(26);
    vecveci S(D,veci(26));
    veci T(D);
    REP(i,26) cin >> C[i];
    REP(i,D) REP(j,26) cin >> S[i][j];
    REP(i,D) {
        T[i] = rand()%26;
    }
    int M; M = 1e5;
    veci B(M),Q(M);
    REP(i,M) {
        B[i] = rand()%D;
        Q[i] = rand()%26;
    }

    veci last_d(26);
    ll old_ans = 0;
    REP(i,D) {
        int d = i+1;
        last_d[T[i]] = d;
        old_ans += S[i][T[i]];
        REP(j,26) {
            old_ans -= C[j]*(d-last_d[j]);
        }
    }

    REP(i,M) {
        int old_p = T[B[i]];
        T[B[i]] = Q[i];
        ll score = 0;
        veci last(26);
        REP(j,D) {
            int d = j+1;
            last[T[j]] = d;
            score += S[j][T[j]];
            REP(k,26) {
                score -= C[k]*(d-last[k]);
            }
        }
        if(old_ans < score) {
            old_ans = score;
        }
        else {
            T[B[i]] = old_p;
        }
    }
    REP(i,D) cout << T[i]+1 << endl;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}

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

    string s;
    cin >> s;
    reverse(ALL(s));
    std::cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3000
#include "bits/stdc++.h"
 
using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main(){

    string N;
    cin >> N;
    string rN = N;
    reverse(N.begin(), N.end());
    
    if(N == rN){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

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

int n,S,l,r,x[100010],p[100010],la;
long long ans,cntl,cntr;

int gabs(int x) {return x<0?-x:x;}

int main()
{
	scanf("%d%d",&n,&S);
	for (int i=1; i<=n; i++) scanf("%d%d",&x[i],&p[i]);
	if (x[1]>S) return printf("%d\n",x[n]-S),0;
	if (x[n]<S) return printf("%d\n",S-x[1]),0;
	l=1,r=n,cntl=cntr=0;
	if (p[1]<p[n]) l++,cntr+=p[1],la=x[1];
	else r--,cntl+=p[n],la=x[n];
	while (x[l]<S&&x[r]>S)
	{
		if (cntl+p[l]<cntr+p[r]) ans+=gabs(la-x[l]),la=x[l],cntr+=cntl+p[l++],cntl=0;
		else ans+=gabs(la-x[r]),la=x[r],cntl+=cntr+p[r--],cntr=0;
	}
	if (x[l]<S) ans+=gabs(la-x[l])+S-x[l];
	else ans+=gabs(la-x[r])+x[r]-S;
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
struct edge
{
        int to, c, h, r;
};
 
struct node
{
        int v, c, h;
        bool operator<(const node &u) const {
                if(c != u.c) return c > u.c;
                return h > u.h;
        }
};
 
int n, m, h, k, s, t, p;
int pass[256], done[128][32], ps[256];
vector<edge> G[128];
 
int dijkstra(int f, int ub)
{
        priority_queue<node> q;
        q.push((node){s,pass[f],0});
        memset(done,0,sizeof(done));
        
        while(!q.empty()) {
                node u = q.top(); q.pop();
                if(u.v == t or u.c >= ub) return u.c;
                if(done[u.v][u.h]) continue;
                done[u.v][u.h] = 1;
                
                for(auto &e: G[u.v]) {
                        if(u.h+e.h > h) continue;
                        if(f&(1<<e.r)) q.push((node){e.to, u.c, u.h+e.h});
                        else q.push((node){e.to, u.c+e.c, u.h+e.h});
                }
        }
        return 1e9;
}
 
int solve()
{
        pass[0] = 0;
        int ans = 1e9;
        for (int i = 0; i < 1<<k; i++) {
                if(pass[i] >= ans) continue;
                ans = min(ans, dijkstra(i, ans));
                for (int j = 0; j < p; j++) {
                        pass[i|ps[j]] = min(pass[i|ps[j]], pass[i]+pass[ps[j]]);
                }
        }
 
        return ans < 1e9? ans: -1;
}
 
void init()
{
        for (int i = 0; i < 128; i++) G[i].clear();
        fill(pass,pass+256,1e9);
}
 
bool input()
{
        cin >> n >> m >> h >> k;
        if(!n) return 0;
        init();
        for (int i = 0; i < m; i++) {
                int a, b, c, h, r;
                cin >> a >> b >> c >> h >> r;
                --a; --b; --r;
                G[a].push_back((edge){b,c,h,r});
                G[b].push_back((edge){a,c,h,r});
        }
        cin >> s >> t >> p;
        --s; --t;
        for (int i = 0; i < p; i++) {
                int l, d, a, as = 0;
                cin >> l >> d;
                for (int j = 0; j < l; j++) {
                        cin >> a;
                        as |= 1<<(a-1);
                }
                ps[i] = as;
                pass[as] = d;
        }
        return 1;
}
 
int main()
{
        while(input()) cout << solve() << endl;
        return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    rep(i,n) cin >> a.at(i);
    for(int i = k; i < n; i++){
        if(a.at(i) > a.at(i-k)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4840
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int m;//正座を構成するm個の星
int n;//写真に写ってる全てのn個の星

typedef pair<int,int> P;

int main()
{
  while(cin >>m,m){
  int x,y;
  vector<P> seiza;
  vector<P> board;
  for(int i = 0;i <m;i++){
    cin >>x>>y;
    seiza.push_back(P(x,y));
  }
  cin >>n;
  for(int i = 0;i < n;i++){
    cin>>x>>y;
    board.push_back(P(x,y));
  }
  map<P,int> Map;
  for(int i =0;i <board.size();i++){
    for(int j = 0;j <seiza.size();j++){
      int dx = board[i].first-seiza[j].first;
      int dy = board[i].second-seiza[j].second;
      Map[P(dx,dy)]++;
    }
  }
  for(map<P,int>::iterator it =Map.begin();it !=Map.end();it++){
    if(it->second ==seiza.size()){
      x =it->first.first;
      y =it->first.second;
      break;
    }
  }
  cout <<x<<" "<<y<<endl;
  }
  return 0;
}

Measured memory_bytes: 13460
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    lateinit var dfs: (Int, Int) -> Unit

    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val S = sc.next()

        var ans = 0
        S.forEach { s ->
            ans += if (s == '+') 1 else -1
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 29472
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ld long double
#define endl "\n"
using namespace std;

int32_t main() {
  int n;
  cin>>n;
  // int a[n];
  // for(int i = 0;i < n;i++) cin>>a[i];
  cout<<(n>=30 ? "Yes" : "No");
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3528
n,w = map(int,input().split())
l =[list(map(int,input().split())) for i in range(n)]

dp = [[[0]*(3*n+1) for i in range(n+1)] for j in range(n+1)]
s = l[0][0]

for i in range(n):
    dt = l[i][0]-s
    for j in range(n):
        for k in range(3*n+1):
            if k -dt >= 0:
                dp[i+1][j+1][k] = max(dp[i][j+1][k],dp[i][j][k-dt]+l[i][1])
            else:
                dp[i+1][j+1][k] = dp[i][j+1][k]

ans = 0
for i in range(1,n+1):
    for j in range(3*n+1):
        if i*s+j <= w:
            ans = max(ans,dp[-1][i][j])
print(ans)

Measured memory_bytes: 68700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> c(n);
    REP(i,n-1){
        int a;cin >> a;
        a--;
        c[a]++;
    }
    REP(i,n){
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 3960
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
divisor = 1000000007
# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())
t = []

for i in range( len(s) ):
    if s[i] == '?':
        t.append(-1)
    else:
        t.append(int(s[i]))

dp = [[0 for i in range(13)] for i in range(100005)]
dp[0][0]=1
for i in range(len(s)):
    for j in range(10):
        if t[i] == -1 or t[i] == j:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] = dp[i+1][j] % divisor

print(dp[len(s)][5])


Measured memory_bytes: 72712
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())


def main():
    S = readline().rstrip()
    ans =S + "s" if S[-1] != "s" else S + "es"
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61736
#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>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else if (x >= a) cout << 10 << endl;
	return 0;
}

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

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

use std::cmp::{max, min};

fn main() {

  let n: i64 = read();
  println!("{}", n.pow(3));
}


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

int main()
{
	int k, s;
	cin >> k >> s;
	long long int ans = 0;
	for(auto x = max(0, s - k * 2); x <= k; ++x){
		ans += max(0, min(s - x, k) - max(0, s - x - k) + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=100005;
///Code begin..................................................................


int main ()
{
    int a, b;
    cin>>a>>b;
    cout<<b+b-a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

LL table[25];
int D, L_D, L, ans;

inline void init()
{
	table[ 0 ] = 1;
	for( int i = 1 ; i <= 18 ; i++ ) table[ i ] = table[ i - 1 ] * 10;
}

inline void solve()
{
	int n = ( L >> 1 ) - 1, ret = ( L & 1 ) ? 10 : 1;
	LL cur = D, t;
	for( int i = 0, f = 1 ; i <= n ; i++ )
	{
		t = table[ L - 1 - i ] - table[ i ];
		if( cur >= 0 ) f = 1; else f = -1, cur = -cur;
		LL d = cur / t, c = cur - d * t, v = c % table[ i + 1 ];
		if( v )
		{
			if( v ^ 9 * table[ i ] ) return ;
			d++, c -= t;
		}
		if( d >= 10 ) return ;
		cur = c * f;
		ret *= 10 - ( !i && ( !d || f > 0 ) ) - d;
	}
	if( cur ) return;
	ans += ret;
}

inline int solve(int D)
{
	ans = L_D = 0; ::D = D; int t = D;
	if( D % 9 ) return 0;
	while( t ) t /= 10, L_D++;
	for( L = L_D ; L <= ( L_D << 1 ) ; L++ ) solve();
	return ans;
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	init();
	printf( "%d\n", solve( read() ) );
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}

int main(){
	int n,a,b,c;
	cin >> n >> a >> b >> c;
	vector<int> l(n);
	REP(i,n) cin >> l[i];
	
	int ans = 100000000;
	for(int t=0; t < (int)pow(4,n); t++){
		int ta=0,tb=0,tc=0,cost=0;
		REP(i,n){
			int type = (t/(int)pow(4,i))%4;
			if(type == 0){
				if(ta!=0) cost+=10;
				ta += l[i];
			}else if(type==1){
				if(tb!=0) cost+=10;
				tb += l[i];
			}else if(type==2){
				if(tc!=0) cost+=10;
				tc += l[i];
			}
		}
		if(ta*tb*tc==0) continue;
		
		cost += abs(a-ta)+abs(b-tb)+abs(c-tc);
		
		chmin(ans, cost);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++){
    ans+=s[i]-48;
  }
  if(ans%9==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3740
#include<stdio.h>
#include<stdlib.h>

#define POS(i,j) ((i)*w+(j))

void assign(int *way,int a,int b,int c,int d){
  way[0]=a;
  way[1]=b;
  way[2]=c;
  way[3]=d;
  return;
}

void run(void){
  int h,w;
  scanf("%d%d",&h,&w);
  int *a=(int *)malloc(sizeof(int)*h*w);
  int i,j;
  for(i=0;i<h*w;i++) scanf("%d",a+i);
  int *way=(int *)malloc(sizeof(int)*4*h*w);
  int wlen=0;
  for(i=0;i<h;i++){
    for(j=0;j<w-1;j++){
      if(a[POS(i,j)]%2==0) continue;
      a[POS(i,j)]--;
      a[POS(i,j+1)]++;
      assign(way+4*wlen,i,j,i,j+1);
      wlen++;
    }
  }
  j=w-1;
  for(i=0;i<h-1;i++){
    if(a[POS(i,j)]%2==0) continue;
    a[POS(i+1,j)]++;
    assign(way+4*wlen,i,j,i+1,j);
    wlen++;
  }
  printf("%d\n",wlen);
  for(i=0;i<wlen;i++){
    printf("%d %d %d %d\n",way[4*i+0]+1,way[4*i+1]+1,way[4*i+2]+1,way[4*i+3]+1);
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>
#include<string.h>

int main(){
  int i,den,num,n,j,ans;
  while(scanf("%d %d %d",&den,&num,&n)!=EOF){
    den=den%num;
    for(i=0,ans=0,j=den;i<n;i++){
      j*=10;
      if(j>=num){
	ans+=j/num;
	j=j%num;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
w, h, x, y = gets.strip.split.map(&:to_i)

flag = (w % 2 == 0) && (w / 2 == x) && (h % 2 == 0) && (h / 2 == y)

puts("#{w.to_f * h.to_f / 2} #{flag ? 1 : 0}")

Measured memory_bytes: 14240
using System;
using System.Linq;

public class App
{
    public static void Main(string[] args)
    {
        int[] a = new int[5];
        a[0]=int.Parse(Console.ReadLine());
        a[1]=int.Parse(Console.ReadLine());
        a[2]=int.Parse(Console.ReadLine());
        a[3]=int.Parse(Console.ReadLine());
        a[4]=int.Parse(Console.ReadLine());
      	Console.WriteLine(a.Sum(i=>((i-1)/10+1)*10)-10+a.Min(i=>(i-1)%10+1));
    }
}


Measured memory_bytes: 13396
# coding: utf-8
# Here your code



N = input()
a = [int(i) for i in input().split()] 
result = 0
first_flag = 1

for i in range(1,len(a)):
    if first_flag == 1:
        if a[i-1] > a[i]:
            first_flag = 2
        elif a[i-1] < a[i]:
            first_flag = 3
    elif first_flag == 2:
        if a[i-1] < a[i]:
            result += 1
            first_flag = 1
    elif first_flag == 3:
        if a[i-1] > a[i]:
            result += 1
            first_flag = 1    

print(result+1)


Measured memory_bytes: 14224
import copy
from collections import deque

####入力
H,W = map(int,input().split())

#gridの定義
grid = []
for i in range(H):
  S = input()
  grid.append( [S[i] for i in range(W) ])
####入力終了

#distの設定
dist = [[0 for i in range(W)] for j in range(H)]

#l_blackの設定
l_black = deque([])
for i in range(H):
  for j in range(W):
    if grid[i][j] == "#":
      l_black.append( [i,j] ) # [行,列]

#探索
max_d = 0

while len(l_black) > 0:
  #vは黒マスの座標 
  while len(l_black) > 0:
    v = l_black.popleft()
    #iはvの上下左右のマスの座標[行,列]
    for i in [ [v[0]+1,v[1]] , [v[0],v[1]+1] , [v[0]-1,v[1]] ,[v[0],v[1]-1] ]:
      #場外アウトの場合はスルー
      if (i[1]<0 or i[0] <0 or i[0]>=H or i[1] >= W ):
        continue
      #移動先がもう黒マスの場合スルー
      if grid[i[0]][i[1]] == "#":
        continue
      #移動先が白マスならばそこの座標を黒マスにして距離を記録する
      if grid[i[0]][i[1]] == ".":
        #黒マスにする
        grid[i[0]][i[1]] = "#"
        #新たに黒鱒となった座標をl_blackに追加
        l_black.append(i)
        #距離の記録
        dist[i[0]][i[1]] = dist[v[0]][v[1]] + 1
        max_d = max(max_d,dist[i[0]][i[1]])
print(max_d)  

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

const int N=100;

int x[N],y[N];
vector <pair <int, int>> q;

int main(){
	int n; cin>>n;
	for (int i=1;i<=n;i++)
		scanf("%d%d",x+i,y+i);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++){
			int tx=x[i]-x[j],ty=y[i]-y[j];
			if (tx<0) tx=-tx,ty=-ty;
			else if (tx==0) ty=abs(ty);
			q.push_back(make_pair(tx,ty));
		}
	sort(q.begin(),q.end());
	pair <int, int> last(0,0);
	int cnt=0,s=0;
	for (auto &val: q){
		if (val==last) cnt++;
		else cnt=1;
		last=val; s=max(s,cnt);
	}
	cout<<n-s<<endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    x=input()
    if x[0]=='M':
        m+=1
    elif x[0]=='A':
        a+=1
    elif x[0]=='R':
        r+=1
    elif x[0]=='C':
        c+=1
    elif x[0]=='H':
        h+=1
    else:
        continue

ans=0
ans+=(m*a*r)
ans+=(m*a*c)
ans+=(m*a*h)
ans+=(m*c*r)
ans+=(m*h*r)
ans+=(m*c*h)
ans+=(a*r*c)
ans+=(a*r*h)
ans+=(a*c*h)
ans+=(r*c*h)
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

	    long N = Long.parseLong(scanner.next());
	    StringBuilder sb=new StringBuilder();
	    do {
	    	if (N % -2 == 0) {
	    	    sb.append("0");
	    	    N = N / -2;
	    	} else {
	    		sb.append("1");
	    		N--;
	    		N = N / -2;
	    	}
	    }while(N != 0);

        StringBuffer sbf = new StringBuffer(sb.toString());
        System.out.print(sbf.reverse().toString());
	}

}


Measured memory_bytes: 35580
import java.util.Scanner;
public class Main {
	public static void main(String[] args)
	{
		int a,b;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();

		b = sc.nextInt();


		if( b%a ==0) {
			System.out.println(a+b);


		}else {
			System.out.println(b-a);
		}

	}
}

Measured memory_bytes: 23636
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, k) = readLongList()
    val ans = if (k % 2 == 0L) {
        val even = n / k
        val odd = n / (k / 2) - even
        odd * odd * odd + even * even * even
    } else {
        val tmp = n / k
        tmp * tmp * tmp
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36428
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;

    
int main()
{   
    int N, M;
    cin >> N >> M;
    int a, b;
    a = 1;
    b = M;
    for(int i=0; i<floor(M/2.0); i++){
       
        std::cout << a << " " << b << std::endl;
        a ++;
        b --;
    }
    
    a = M+1;
    b = 2*M+1;
    for(int i=0; i<ceil(M/2.0); i++){
       
        std::cout << a << " " << b << std::endl;
        a ++;
        b --;
    }

  
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    for (int i = 0; i < a.size()-1; i++)
    {
        if(a[i]==a[i+1])
        {
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int64_t N, K;
  cin >> N >> K;
  int64_t result = 0;
  while (N > 0) {
    N /= K;
    result++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() { 
  string A,C,R;
  C="ABC";
  R="ARC";
  cin >>A;
  if(A == C){
    cout<<R<<endl;
    }
  if(A == R){
    cout<<C<<endl;
    }
  return 0;
  }
  



Measured memory_bytes: 3596