akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
using namespace std;
int read() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -f;
		ch = getchar();
	} while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return f * x;
}
const int N = 55;
int n, m, q;
int a[N], b[N], c[N], d[N];
int A[N];
int ans = 0; 
void dfs(int cur) {
	if (cur == n + 1) {
		int sum = 0;
		for (int i = 1; i <= q; ++i) {
			if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
		}
		ans = max(ans, sum);
		return ; 
	}
	for (int i = A[cur - 1]; i <= m; ++i) {
		A[cur] = i;
		dfs(cur + 1);
	}
}
int main() {
	cin >> n >> m >> q;
	for (int i = 1; i <= q; ++i)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	A[0] = 1; 
	dfs(1);
	cout << ans << endl;
	return 0;
}






Measured memory_bytes: 3636
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] ac = new boolean[n];
        int[] wa = new int[n];
        int acSum = 0;
        int waSum = 0;
        for (int i = 0; i < m; i++) {
            int index = sc.nextInt() - 1;
            boolean isAc = sc.next().equals("AC");
            if (ac[index]) {
                continue;
            }
            if (isAc) {
                acSum++;
                ac[index] = true;
                waSum += wa[index];
            } else {
                wa[index]++;
            }
        }
        System.out.println(acSum + " " + waSum);
    }
}

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

int N;
int a[(int)1e5 + 1];

int main() {
    cin >> N;
    rep(i, N) cin >> a[i + 1];

    // int d[(int)1e5 + 1];
    map<int, int> d;

    int idx = 1;
    int cnt = 0;

    // 押したかどうか
    while (true) {
        // d[idx] = a[idx];
        // cout << idx << endl;
        // printf("idx: %d a[idx] %d\n", idx, a[idx]);

        if (d.count(idx)) {
            cout << -1 << endl;
            return 0;
        }

        d[idx] = idx;
        idx = a[idx];
        cnt++;

        if (idx == 2) {
            break;
        }
    }

    cout << cnt << endl;
}

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

int main() {
    string s; cin >> s;
    int n = s.size();
    string a;
    string b;
    vector<char> clr = {'0','1'};
    rep(i,n){
        a.push_back(clr[i%2]);
        b.push_back(clr[(i+1)%2]);
    }
    int cnta = 0;
    int cntb = 0;
    rep(i,n){
        if(a[i] == s[i]) cnta ++;
        if(b[i] == s[i]) cntb ++;
    }
    cout << min(cnta,cntb) << endl;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.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; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	ll n, m, l;
	cin >> n >> m >> l;
	ll a[n][m], b[m][l];
	rep(i, n) rep(j, m) cin >> a[i][j];
	rep(i, m) rep(j, l) cin >> b[i][j];

	ll ans[n][l];
	rep(i, n) rep(j, l) ans[i][j] = 0;
	rep(i, n) rep(j, l)
	{
		rep(k, m)
			ans[i][j] += a[i][k] * b[k][j];
	}

	rep(i, n)
	{
		rep(j, l)
		{
			if(j == 0) cout << ans[i][j];
			else cout << ' ' << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3380
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, p;
  while(1){
    cin >> n >> p;
    if(n==0){
      break;
    }
    vector<int> a(n,0);
    int i = 0, tmp = p;
    while(1){
      if(tmp>0){
        tmp--;
        a[i]++;
      }else{
        if(a[i]==p){
          cout << i << endl;
          break;
        }
        tmp += a[i];
        a[i] = 0;
      }
      i++;
      if (i == n) {
        i = 0;
      }
    }
  }
  return 0;
}


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

public class Main {
	static int dp[][] = new int[1005][1005]; 
	static char a[][] = new char[1005][1005];
	static int vis[][] = new int[1005][1005]; 
	static int n , m; 
	public static int fun(int i , int j) {
		if(dp[i][j] != -1)
			return dp[i][j]; 
		
		if(i >= n || j >= m) 
			return 0;
		if(a[i][j] == '#') 
			return 0; 
		if(i == n-1 && j == m-1) 
			return dp[i][j] = 1; 
	     
		return dp[i][j] = (fun(i+1,j) + fun(i , j+1)) % (int) (1e9 + 7); 
	}
	
	public static void solve(InputReader in) {
		 n = in.readInt(); 
		 m = in.readInt(); 
		 
		
		for(int i = 0; i<n; i++) {
			char s[] = in.readString().toCharArray(); 
			for(int j = 0; j<m; j++) {
				a[i][j] = s[j]; 
			}
		}
		
		for(int i = 0; i<1005; i++) {
			for(int j = 0; j<1005; j++) {
				dp[i][j] = -1; 
			}
		}
	    System.out.println(fun(0,0)); 
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = 1; 
		while (t-- > 0)
			solve(in);
	}
}

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

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

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

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

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
     
     public String next() {
		return readString();
	}
    
     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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


int main()
{
    long k;
    cin >> k;
    vector<long> queue = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    for (int i = 0; i < k; i++)
    {
        long x = queue[i];
        long l = x % 10;
        if (l == 0)
        {
            queue.push_back(x*10 + l);
            queue.push_back(x*10 + l + 1);
        }
        else if (l == 9)
        {
            queue.push_back(x*10 + 8);
            queue.push_back(x*10 + 9);
        } else
        {
            queue.push_back(x*10 + (l-1));
            queue.push_back(x*10 + l);
            queue.push_back(x*10 + (l+1));
        }
    }
    cout << queue[k-1] << endl;
}

Measured memory_bytes: 3828
import bisect
INF = 10**16
n=int(input())
a=list(map(int,input().split()))
la=[0]
for i in range(n):
    la.append(la[i]+a[i])
la.pop(0)
sa = la[-1]
l=0
r=2
res = INF
for i in range(1,n-2):
    while abs(la[l+1]-(la[i]-la[l+1])) < abs(la[l]-(la[i]-la[l])):
        l += 1

    if r == i:
        r += 1
    while abs((la[r+1] - la[i])-(sa - la[r+1])) < abs((la[r] - la[i])-(sa - la[r])):
        r += 1
    r1 = la[l]
    r2 = la[i] - la[l]
    r3 = la[r] - la[i]
    r4 = sa    - la[r]
    res=min(res,max(r1,r2,r3,r4)-min(r1,r2,r3,r4))
print(res)

Measured memory_bytes: 118484
#include <stdio.h>

int min(int a[]){
    int b = 1;
    if(a[0]<a[1])
        b = 0;
    if(a[b]>a[2])
        b = 2;
    return b;
}

int max(int a[]){
    int b = 1;
    if(a[0]>a[1])
        b = 0;
    if(a[b]<a[2])
        b = 2;
    return b;
}

int main()
{
    int a[3] = {0,0,0};
    int b,c;
    while(scanf("%d",&b)==1){
        c = min(a);
        if(a[c]<b)a[c] = b;
    }
    b = min(a);
    c = max(a);
    printf("%d\n%d\n%d\n",a[c],a[3-b-c],a[b]);
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(), p.end());

  int s, t, u = 0;

  rep(i,n) {
    if (x == p[i]) {
      s = i-1;
      t = i+1;
      u = 1;
    }
  }

  if (u == 0) {
    cout << x << endl;
    return 0;
  }

  int i = 1;
  while (true) {
    int a = x - i, b = x + i;
    if (s >= 0) {
      if (a != p[s]) {
        cout << a << endl;
        return 0;
      }
      s--;
    } else {
      cout << a << endl;
      return 0;
    }
    if (t < n) {
      if (b != p[t]) {
        cout << b << endl;
        return 0;
      }
      t++;
    } else {
      cout << b << endl;
      return 0;
    }
    i++;
  }


  return 0;
}



Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int i = 0, cnt[2] = {};

    while (i < N && S[i] == '<') {
        ++i;
        ++cnt[0];
    }
    
    i = N - 1;
    while (i >= 0 && S[i] == '>') {
        --i;
        ++cnt[1];
    }
    cout << N - min(cnt[0], cnt[1]) << endl;
    return 0;
}

Measured memory_bytes: 3312
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N, X;
vector<int> x_coords;
vector<int> distances;

int get_gcd(int m, int n)
{
    int gcd = 1;
    
    int sm = min(m, n); int lg = max(m, n);
    bool finished = false;

    while (!finished) {
        if (lg % sm == 0) {
            gcd = sm;
            finished = true;
        } else {
           int tmp = sm;
           sm = lg % sm;
           lg = tmp;      
        }
    }

    return gcd;
}

int calc()
{
    // 各x間の距離の最大公約数を求める
    int gcd;
    
    sort(x_coords.begin(), x_coords.end());
    for (int i = 1; i < x_coords.size(); i++) {
        distances.push_back(x_coords[i] - x_coords[i - 1]);
    }

    for (int i = 0; i < distances.size(); i++) {
        if (i == 0) {
            gcd = distances[i];
        } else {
            gcd = get_gcd(distances[i], gcd);
        }
    }
    
    return gcd;
}

int main()
{
    cin >> N >> X;
    x_coords.push_back(X);
    
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        x_coords.push_back(x);
    }
    
    cout << calc() << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> p){
    cout << p.first << " " << p.second << "\n";
}

int main(){
    string s;cin >> s;
    ll n = s.size();
    if(s[n-1] == '1' || s[0] == '0'){
        cout << -1 << endl;
        return 0;
    }
    bool ok = true;
    vector<Pll> ans(n-1);
    queue<ll> q;
    ll cnt = 0;
    rep(i,n/2){
        if(s[i] != s[n-i-2]){ok = false;break;}
        if(s[i] == '0')q.push(i+1);
        else{
            while(q.size()){
                ll t = q.front();q.pop();
                ans[cnt] = {i+1,t};
                cnt++;
            }
            q.push(i+1);
        }
    }
    while(q.size()){
        ll t = q.front();q.pop();
        ans[cnt] = {n/2+1,t};
        cnt++;
    }
    for(int i = n/2 + 2; i <= n; i++){
        ans[cnt] = {n/2+1, i};
        cnt++;
    }
    if(ok){
        rep(i,n-1)print(ans[i]);
    }
    else{print(-1);}
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int n, k, d[40];
vector<long long> s, v;
int main(void){

    cin >> n >> k;
    s.assign(n+1, 0);
    for(int i=1;i<=n;i++){
        cin >> s[i];
        s[i] += s[i-1];
    }

    fill(d, d+40, 0);
    for(int i=1;i<=n;i++){
        for(int j=0;j<i;j++){
            long long t = s[i] - s[j];
            for(int l=0;l<40;l++){
                d[l] += ((t>>l)&1);
            }
            v.push_back(t);
        }
    }
    long long ans = 0;
    for(int j=39;j>=0;j--){
        if(d[j] >= k){
            vector<long long> w;
            fill(d, d+40, 0);
            ans += (1LL<<j);
            for(int i=0;i<v.size();i++){
                if(((v[i]>>j)&1)==1){
                    for(int l=0;l<j;l++){
                        d[l] += ((v[i]>>l)&1);
                    }
                    w.push_back(v[i]);
                }
            }
            v.assign(w.begin(), w.end());
        }
    }
    cout << ans << endl;
}


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

//temmplate------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define ZERO(a) memset(a, 0, sizeof(a))
typedef long long lint;
//------template

int main(){
    int a,b;
    cin >> a >> b;
    string A = "";
    string B = "";
    REP(i,b){
        A += to_string(a);
    }
    REP(i, a){
        B += to_string(b);
    }

    if (A < B){
        cout << A << "\n";
    } else {
        cout << B << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll> 
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
ll cc;
void dfs(ll i,ll j,ll n,ll m,vvl &vi,vector<string> &mat){
	if(i<1 || i>n || j<1 || j>m || vi[i][j] || mat[i][j]=='#')return;
	vi[i][j]=cc;
	dfs(i+1,j,n,m,vi,mat);
	dfs(i-1,j,n,m,vi,mat);
	dfs(i,j-1,n,m,vi,mat);
	dfs(i,j+1,n,m,vi,mat);

}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
	//cin >> T;
	ll t=0;
	while(t++<T){
		ll n,m;
		cin>>n>>m;
		ll x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		vector<string> mat(n+1);
		for(ll i=1;i<=n;i++){
			cin>>mat[i];
			mat[i]=' '+mat[i];
		}
		cc=0;
		vvl vi(n+1,vll(m+1,0));
		for(ll i=1;i<=n;i++){
			for(ll j=1;j<=m;j++){
				if(mat[i][j]=='.' && !vi[i][j]){
					cc++;
					dfs(i,j,n,m,vi,mat);
				}
			}
		}
		map<ll,map<ll,ll>> pr;
		vll adj[cc+5];
		for(ll i=1;i<=n;i++){
			for(ll j=1;j<=m;j++){
				if(mat[i][j]=='#' || vi[i][j]==0)continue;
				for(ll l=-2;l<=2;l++){
					for(ll r=-2;r<=2;r++){
						ll x=i+l,y=j+r;
						if(x<1 || x>n || y<1 || y>m)continue;
						ll cc1=vi[i][j];
						ll cc2=vi[x][y];
						if(cc1==cc2 || pr[cc1][cc2] || cc2==0 || mat[x][y]=='#')continue;
						pr[cc1][cc2]++;
						pr[cc2][cc1]++;
						adj[cc1].pb(cc2);
						adj[cc2].pb(cc1);
					}
				}
			}
		}
		queue<ll> q;
		q.push(vi[x1][y1]);
		vll d(cc+5,INT_MAX);
		d[vi[x1][y1]]=0;
		while(!q.empty()){
			ll u=q.front();
			q.pop();
			for(auto x:adj[u]){
				if(d[x]==INT_MAX){
					d[x]=d[u]+1;
					q.push(x);
				}
			}
		}
		if(d[vi[x2][y2]]==INT_MAX)cout<<-1<<endl;
		else cout<<d[vi[x2][y2]]<<endl;
	}
return 0;
}


Measured memory_bytes: 69592
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;
  bool ok = true;
  for (int i = S.size() - 2; i > 0; i -= 2) {
    for (int j = 0; j < i / 2; j++) {
      if (S.at(j) != S.at(j + i / 2)) {
        break;
      }
      else if (j == i / 2 - 1) {
        cout << i << endl;
        ok = false;
        break;
      }
    }
    if (ok == false) {
      break;
    }
  }
}
          

Measured memory_bytes: 3596
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2;
  return 0;
}


Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
L = [-1]*(N+1)
L[0] = 2
L[1] = 1
def calc(x):
  if L[x] >= 0:
    return L[x]
  else:
    L[x] = calc(x-1)+calc(x-2)
    return L[x]

print(calc(N))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,K=0;
  string a,b,c;
  cin>>N>>a>>b>>c;
  rep(i,N){
    if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
      if(a[i]==b[i]&&b[i]==c[i]){
        
      }else{
        K++;
      }
    }else{
      K+=2;
    }
  }
  cout<<K<<endl;
  return 0;
}


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

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				return;
			}
			String[] write = new String[n];
			for (int i = 0; i < n; i++) {
				write[i] = sc.next();
			}
			for (int i = 0; i < n; i++) {
				char[] tmp = write[i].toCharArray();
				for (int j = 0; j < tmp.length - 1; j++) {
					if (tmp[j] == '.' && tmp[j + 1] != '.') {
						tmp[j] = '+';
					}
				}
				write[i] = String.valueOf(tmp);
			}
			for (int i = 0; i < n; i++) {
				L: for (int j = 0; j < write[i].length(); j++) {
					if (write[i].charAt(j) == '+') {
						for (int k = i + 1; k < n; k++) {
							if (j >= write[k].length() || Character.isLetter(write[k].charAt(j))) {
								break L;
							}
							if (write[k].charAt(j) == '+') {
								for (int l = i + 1; l < k; l++) {
									char[] tmp = write[l].toCharArray();
									tmp[j] = '|';
									write[l] = String.valueOf(tmp);
								}
								break L;
							}
						}
					}
				}
				char[] tmp = write[i].toCharArray();
				for (int j = 0; j < tmp.length; j++) {
					if (tmp[j] == '.') {
						tmp[j] = ' ';
					}
				}
				write[i] = String.valueOf(tmp);
				System.out.println(write[i]);
			}
		}
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

Measured memory_bytes: 283968
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      String str = sc.next();
      String[] C = str.split("");
      
      // 判定
      int red = 0;
      int white = 0;
      int[] whiteCounter = new int[N];
      for(int i = 0; i < N; i++){
        if(C[i].equals("W")){
          white++;
        }else{
          red++;
        }
        whiteCounter[i] = white;
      }
      
      int result = 0;
      if(red > 0){
        result = whiteCounter[red-1];
      }
      
      // 出力
      System.out.println(result);
    }
    

}

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

int main()
{
    int x,y;
    cin >> x >> y;
    bool flag = false;

    for (int i = 0; i <= x; i++) {
        if (2*i + 4*(x - i) == y)
            flag = true;
    }

    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<long long>> shop(N,vector<long long>(2));
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    shop[i][0]=a;
    shop[i][1]=b;    
  }
  stable_sort(shop.begin(), shop.end(), [](auto& x, auto& y){return x[0] < y[0];});
  long long ans=0, num=0;
  for(int i=0; i<N; i++){
    if(num+shop[i][1]>=M){
      ans+=shop[i][0]*(M-num);
      break;      
    }
    num+=shop[i][1];
    ans+=shop[i][0]*shop[i][1];
  }
  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  set<char> t;
  for (int i = 0; i < s.size(); i++) {
    t.insert(s[i]);
  }
  if (s.size() == t.size()) {
    cout << "yes" << endl;
  }
  else {
    cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#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 <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

ll N,u,v;
bool used[100010];
vector<vector<ll>> edge;
vector<ll> leaf;

void bfs(ll s,vector<ll>& d){
  REP(i,N)used[i]=false;
  used[s]=true;
  queue<ll> que;
  que.push(s);
  d[s]=0;
  while(!que.empty()){
    ll x=que.front();que.pop();
    REP(i,edge[x].size()){
      ll y=edge[x][i];
      if(!used[y]){
        used[y]=true;
        d[y]=d[x]+1;
        que.push(y);
      }
    }
  }
}



int main(){
  cin>>N>>u>>v;
  u--;v--;
  vector<ll> du(N);
  vector<ll> dv(N);
  edge=vector<vector<ll>>(N);
  REP(i,N-1){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }

  REP(i,N)if(edge[i].size()==1)leaf.emplace_back(i);

  bfs(u,du);
  bfs(v,dv);
  ll ans=0;
  REP(i,leaf.size()){
    if(du[leaf[i]]<dv[leaf[i]]){
      ans=max(ans,dv[leaf[i]]-1);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8576
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
string s;
cin>>s;
bool ans = true;
rep(i,s.size()){
    if(i%2==0){
        if(s[i]=='L')ans=false;
    }else{
        if(s[i]=='R')ans=false;
    }
}
    if(ans){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

class SegTree{
    vector<pair<ll, int>> st;

    ll N;
    int root(int x) const{
        return x / 2;
    }
    int left(int x) const {
        return x*2 + 1;
    }
    int right(int x) const{
        return 2*x + 2;
    }
    pair<ll, int> min_s(int a, int b, int k, int l, int r) const{
        ll ans = 0;
        if(r <= a || b <= l) return {INF, -1};
        if(a <= l && r <= b) return st[k];
        else{
            auto vl = min_s(a, b, left(k), l, (l+r)/2);
            auto vr = min_s(a, b, right(k), (l+r)/2, r);
            return min(vl, vr);
        }
    }

public:
    SegTree(const vector<ll>& X) :st() {
        ll k = X.size();
        N = 1;
        while(N < k) N *= 2;
        st.resize(2*N-1, {INF, INF});
        for (int i = 0; i < X.size(); ++i) {
            st[i+N-1] = {X[i], i};
        } // end i
        for (int i = N - 2; i >= 0; --i) {
            st[i] = min(st[left(i)] , st[right(i)]);
        } // end i
    }

    pair<ll, int> get_min(int a, int b) const{
        return min_s(a, b, 0, 0, N);
    }

};

ll f(int l, int r, const SegTree& a){
    // sum sum min a[l, r)
    if(r - l < 1) return 0;
    auto mini = a.get_min(l, r);
    int mi_i = mini.second;
    int mi = mini.first;

    ll L = mi_i - l; ll R = r - mi_i-1;
    ll ret = mi * (L + 1) * (R + 1);
    return ret + f(l, mi_i, a) + f(mi_i+1, r, a);

}

void sub_main(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    vector<ll> a;
    for (int i = 0; i < N; ++i) {
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    } // end i
    SegTree sg(a);
    cout << f(0, N, sg) << endl;
    
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        sub_main(fs);
    }
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 57072
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll V, E, s, t, w;

typedef int Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 g:隣接リスト,r:最小全域木の始点
//戻値 total:最小全域木の重み,T:最小全域木の辺集合
pair<Weight, Edges> prim(const Graph &g, int r = 0) {
	int n = g.size();
	Edges T;
	Weight total = 0;
	vector<bool> visited(n);
	priority_queue<Edge> Q;
	Q.push(Edge(-1, r, 0));    //始め、-1とrを結ぶ辺があると考える
	while (!Q.empty()) {
		Edge e = Q.top(); Q.pop();
		if (visited[e.dst]) continue;
		T.push_back(e);
		total += e.weight;
		visited[e.dst] = true;
		for (auto f = g[e.dst].begin(); f != g[e.dst].end(); ++f) if (!visited[f->dst]) Q.push(*f);
	}
	return pair<Weight, Edges>(total, T);
}

int main() {
	cin >> V >> E;
	Graph g(V);
	for (int i = 0; i < E; i++) {
		cin >> s >> t >> w;
		g[s].push_back(Edge(s, t, w));
		g[t].push_back(Edge(t, s, w));
	}
	cout << prim(g).first << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];
    sort(d.begin(), d.end());

    long long left = 0, right = n;
    for (int i = 0; i < n; i++) {
        left++;
        right--;
        if (d[i] == d[i + 1] && i != n - 1) continue;
        if (left == right) {
            cout << d[i + 1] - d[i] << endl;
            return 0;
        }
    }

    /*
    for (int i = 0; i < n; i++) {
        cout << d[i] << " ";
    }
    cout << endl;
    */
    
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
#define print(x) cout<<#x<<"="<<x<<'\n'
#define print2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define print3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mp make_pair
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<long double>
#define vvi vector<vector<long double>>
#define vpii vector<pii>
using namespace std;

vi graph[101];
int level[101];
bool vis[101];

int main(){
	int t=1;
	// cin>>t;
	while(t--){
		int n;
		cin>>n;
		// long double temp=((long double)(1))/((long double)(3));
		cout<<setprecision(16);
		// cout<<temp;
		vi a(n);
		int heads=n/2+1;
		vvi dp(n+1,vi(heads+1));
		rep(i,n) cin>>a[i];
		fr(i,0,n){
			fr(j,0,heads){
				if(j==0){
					dp[i][j]=1;
					continue;
				}
				if(i==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=a[i-1]*dp[i-1][j-1]+(1-a[i-1])*dp[i-1][j];
			}
		}
		cout<<dp[n][heads]<<endl;
	}
	return 0;
}


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

int main(){
    int n;ll k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> che(n,0);
    vector<int> ans;
    ans.push_back(1);
    che[0] = 1;
    int now = a[0];
    int cnt = 2;
    while(che[now-1] == 0){
        ans.push_back(now);
        che[now-1] = cnt;
        now = a[now-1];
        cnt++;
    }
    int sz = cnt-che[now-1];
    if(k<cnt-1) cout << ans[k];
    else{
        int l = (k-che[now-1]+1)%sz;
        cout << ans[l+che[now-1]-1] << endl;
    }
}

Measured memory_bytes: 5860
def digit_sum(x):
  string_x = str(x)
  total = 0
  for char in string_x:
    total += int(char)
  return total
a, b, c = map(int, input().split())

sum=0
for i in range(1,a+1):
    if(digit_sum(i)>=b and digit_sum(i)<=c):
        sum=sum+i

print(sum)
    


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdbool.h>
 
typedef struct {
    char suit;
    int num;
} card;
 
void BubbleSort(int n, card cards[]);
void SelectionSort(int n, card cards[]);
void swap(card *one, card *another);
bool judge_stable(int n, card cards01[], card cards02[]);
 
int main(void)
{
    int i;
 
    int n;
    scanf("%d", &n);
 
    card cards01[36], cards02[36];
    for (i = 0; i < n; i++) {
        scanf(" %c%d", &cards01[i].suit, &cards01[i].num);
        cards02[i] = cards01[i];
    }
 
    BubbleSort(n, cards01);
    for (i = 0; i < n; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%c%d", cards01[i].suit, cards01[i].num);
    }
    printf("\n");
    printf("Stable\n");
 
    SelectionSort(n, cards02);
    for (i = 0; i < n; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%c%d", cards02[i].suit, cards02[i].num);
    }
    printf("\n");
    bool isStable = judge_stable(n, cards01, cards02);
    if (isStable) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
 
    return 0;
}
 
void BubbleSort(int n, card cards[])
{
    int i, j;
 
    for (i = 0; i < n; i++) {
        for (j = n - 1; j > i; j--) {
            if (cards[j].num < cards[j - 1].num) {
                swap(&cards[j], &cards[j - 1]);
            }
        }
    }
}
 
void SelectionSort(int n, card cards[])
{
    int i, j;
    int min;
 
    for (i = 0; i < n; i++) {
        min = i;
        for (j = i; j < n; j++) {
            if (cards[j].num < cards[min].num) {
                min = j;
            }
        }
        swap(&cards[i], &cards[min]);
    }
}
 
void swap(card *one, card *another)
{
    card tmp = *one;
    *one = *another;
    *another = tmp;
}
 
bool judge_stable(int n, card cards01[], card cards02[])
{
    int i;
    for (i = 0; i < n; i++) {
        if (cards02[i].suit != cards01[i].suit) {
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;

#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
 
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

#define N 20004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}

int main(){fastio
    calc();
    ll n,k;cin>>n>>k;
    ll a[k];rep(i,0,k-1)cin>>a[i];
    ll dp[k+1][n+1];memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,0,k-1){
        rep(j,0,n){
            rep(p,0,a[i]){
                if(j+p<=n){
                    Add(dp[i+1][j+p],mod(dp[i][j]*comb(n-j,p))*comb(n-p,a[i]-p));
                }
            }
        }
    }
    /*
    rep(i,0,k){
        rep(j,0,n){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    cout<<mod(dp[k][n])<<endl;
    
    return 0;
}


Measured memory_bytes: 768
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const n = Number(stdin.split('\n')[0])
const [, ...w] = stdin.trim().split('\n')

const noDupWords = _ => {
  let res = true
  w.forEach((e,i)=>{
    w.forEach((x, j) =>{
      if(e === x && i !== j){
        res = false
      }
    })
  })
  return res
}

const shiritori = _ => {
  for (let i = 1; i < w.length; i++) {
    const s = w[i]
    const bs = w[i-1]

    const tail = bs[bs.length - 1]
    const head = s[0]

    if(tail !== head){
      return false
    }
  }
  return true
}

console.log(shiritori()&&noDupWords() ? 'Yes' : 'No')


Measured memory_bytes: 7628
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;

int s[112345];
int main()
{
	int i,n;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>s[i];
	}
	int ss;
	ss=__gcd(s[0],s[1]);
	for(i=2;i<n;i++){
		ss=__gcd(ss,s[i]);
	}
	cout<<ss<<endl;
	return 0;
}


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

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = Math.abs(A-B);
    if(C % 2 == 0) out.println(C / 2 + Math.min(A,B) );
    else out.println("IMPOSSIBLE");
  }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define rp(p) for(int k = 0; k < p; k++)
#define it(q) for(auto j = q.begin(); j != q.end(); j++)
#define f float
#define s string 
#define vi vector<int>
#define vs vector<string>
#define ll long long
#define pb push_back
using namespace std;
   
int main(){
	ll n;
	cin >> n;
	int count = 0;
	while(n--){
		int a,b;
		cin >> a;
		cin >> b;
		if(a == b){
			count++;
		}
		else{
			count = 0;
		}
		if(count == 3){
			cout << "Yes" << endl;
			break;
		}
	}
	if(count != 3){
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main() {
   int H,W;
   while(1){
	   cin>> H >> W;
	   if(W == 0 && H == 0){ break; }
   for (int i=0 ; i<H ; i++){
	   for (int j=0 ; j<W ; j++){
		   if((i+j)%2==0){
			   cout<<"#";
		   }
		   else {
			   cout <<".";
		   }
	   };
	   cout << endl;
   };
   cout << endl;
  }
return 0;
}


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

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 ll = long long;

constexpr int MAX_N = 100;
constexpr int MAX_V = 1e5;
constexpr ll INF = 1LL << 60;

ll dp[MAX_N+1][MAX_V+1];
int w[MAX_N], v[MAX_N];

int main() {
  int N, W;
  cin >> N >> W;

  fill_n(dp[0], (MAX_N+1)*(MAX_V+1), INF);
  dp[0][0] = 0;

  for (int i{}; i < N; ++i) {
    cin >> w[i] >> v[i];
    for (int j{}; j <= MAX_V; ++j) {
      if (j >= v[i])
        chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
      chmin(dp[i+1][j], dp[i][j]);
    }
  }

  for (int j{MAX_V}; j >= 0; --j) {
    if (dp[N][j] <= W) {
      cout << j << endl;
      break;
    }
  }

  return 0;
}


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

int main() {
    int N, K; cin >> N >> K;
    map<int, int> m;
    for (int i = 0; i < N; i++) {
        m[i] = 0;
    }
    for (int i = 0; i < K; i++) {
        int d; cin >> d;
        vector<int> a(d);
        for (int i = 0; i < d; i++) {
            cin >> a[i]; a[i]--;
            m[a[i]] ++;
        }
    }
    int num = 0;
    for (int i = 0; i < N; i++) {
        if (m[i] == 0) num ++; 
    }
    cout << num << endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back
 
using namespace std;

int main(){

    string s,t;
    cin >> s >> t;

    int ans = 0;
    int n = s.size();

    rep(i,n){

        if(s[i] == t[i]) ans ++;
    }

    cout << ans <<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    
    long long l[100];
    l[0]=2;
    l[1]=1;
    for(int i=2;i<100;i++){
        l[i]=l[i-1]+l[i-2];
    }
    
    cout<<l[n]<<endl;
    
    return 0;
}








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

int main() {
	int a; int b; int c; int d;
	cin >> a >> b >> c >> d;
	if (abs(a - b) <= d && abs(b - c) <= d) {
		cout << "Yes" << endl;
	} else if (abs(a - c) <= d) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            WriteLine(s.Substring(0, s.Length - 8));
        }

    }

    public struct Pair
    {
        public Pair(int a, int b)
        {
            this.a = a;
            this.b = b;
        }
        public int a;
        public int b;
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17292
import java.util.*;

class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int k=sc.nextInt();
		List<Integer>list=new ArrayList<Integer>();
		int sum=0;
		do{
			list.add(n%k);
			n/=k;
		}while(n>0);
		System.out.println(list.size());
	}
}

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

int N;

int main(){
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end());

    cout <<  A.at(A.size()-1) - A.at(0)  << endl;
}

Measured memory_bytes: 3588