akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int R = sc.nextInt();
			if (R == 0) break;
			int C = sc.nextInt();
			int Q = sc.nextInt();
			int[][] G = new int[R][C];
			int[][] tr = new int[C][R];
			for (int i = 0; i < R; ++i) {
				for (int j = 0; j < C; ++j) {
					tr[j][i] = G[i][j] = Integer.parseInt(sc.next());
				}
			}
			int ru = 1;
			while (ru < C * 2) {
				ru *= 2;
			}
			int[][] row = new int[R][ru];
			for (int i = 0; i < R; ++i) {
				build(G[i], row[i]);
			}
			int cu = 1;
			while (cu < R * 2) {
				cu *= 2;
			}
			int[][] col = new int[C][cu];
			for (int i = 0; i < C; ++i) {
				build(tr[i], col[i]);
			}
			for (int i = 0; i < Q; ++i) {
				int R1 = Integer.parseInt(sc.next());
				int C1 = Integer.parseInt(sc.next());
				int R2 = Integer.parseInt(sc.next());
				int C2 = Integer.parseInt(sc.next());
				int ans = Integer.MAX_VALUE;
				if (R2 - R1 < C2 - C1) {
					for (int j = R1; j <= R2; ++j) {
						ans = Math.min(ans, get(row[j], 0, C1, C2 + 1, 0, ru / 2));
					}
				} else {
					for (int j = C1; j <= C2; ++j) {
						ans = Math.min(ans, get(col[j], 0, R1, R2 + 1, 0, cu / 2));
					}
				}
				System.out.println(ans);
			}
		}
	}

	static void build(int[] in, int[] out) {
		for (int i = 0; i < in.length; ++i) {
			out[out.length / 2 - 1 + i] = in[i];
		}
		for (int i = in.length; i < out.length / 2; ++i) {
			out[out.length / 2 - 1 + i] = Integer.MAX_VALUE;
		}
		for (int i = out.length / 2 - 2; i >= 0; --i) {
			out[i] = Math.min(out[i * 2 + 1], out[i * 2 + 2]);
		}
	}

	static int get(int[] tree, int cur, int f, int e, int left, int right) {
		if (right <= f || e <= left) return Integer.MAX_VALUE;
		if (f <= left && right <= e) return tree[cur];
		int mid = (left + right + 1) / 2;
		return Math.min(get(tree, cur * 2 + 1, f, e, left, mid), get(tree, cur * 2 + 2, f, e, mid, right));
	}
}

Measured memory_bytes: 206164
S = list(input())
T = list(input())
pos = []
for i in range(len(S)-len(T)+1):
    if S[i] == T[0] or S[i] == '?':
        flag = 1
        for j in range(len(T)):
            if not T[j] == S[i+j] and not S[i+j] == '?':
                flag = 0
                break
        if flag:
            pos.append(i)

if not pos:
    print('UNRESTORABLE')
    exit()

words = []
for p in pos:
    word = S[0:p] + T + S[p+len(T):]
    for i in range(len(word)):
        if word[i] == '?':
            word[i] = 'a'
    words.append(word)
words.sort()
print("".join(words[0]))


Measured memory_bytes: 9080
def create_fact_mod(num_max, mod)
    $fmod = Array.new(num_max + 1)
    $fmod[0] = 1
    $fmod[1] = 1
    (2..num_max).each do |i|
        $fmod[i] = ($fmod[i - 1] * i) % mod
    end
end

def create_seq_inv_mod(num_max, mod)
    $simod = Array.new(num_max + 1)
    $simod[0] = 1
    $simod[1] = 1
    (2..num_max).each do |i|
        $simod[i] = (mod - mod / i) * $simod[mod % i] % mod
    end
end

def create_fact_inv_mod(num_max, mod)
    $fimod = Array.new(num_max + 1)
    $fimod[0] = 1
    $fimod[1] = 1
    (2..num_max).each do |i|
        $fimod[i] = ($fimod[i - 1] * $simod[i]) % mod
    end
end

def create_mod_tables(n, mod)
    create_fact_mod(n, mod)
    create_seq_inv_mod(n, mod)
    create_fact_inv_mod(n, mod)
end

def comb_mod(n, k, mod)
    return $fmod[n] * $fimod[n - k] * $fimod[k] % mod
end


H, W, A, B = gets.split.map(&:to_i)
MOD = 10**9+7

create_mod_tables(H+W, MOD)

sum = 0
i = 1
loop do
    w = B + i
    h = A + i
    break if w > W || h > H
    c1 = comb_mod(H-h+w-1, w-1, MOD)
    c2 = comb_mod(h+W-w-1, h-1, MOD)
    sum += c1 * c2 % MOD
    sum %= MOD
    i += 1
end
puts sum

Measured memory_bytes: 6524
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589

signed main() {
    quickie 
    string s ;
    cin >> s ;
    if(s == "ARC") cout << "ABC" ;
    else  cout << "ARC" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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

Measured memory_bytes: 3612
#include <stdio.h>
int main() {
  int n,a[101]={0},count=1,ans=0,i;
  scanf("%d",&n);
  for (i=1; i<=n; i++) {
    scanf("%d",&a[i]);
    if (a[i]==a[i-1]) {
      count++;
    } else {
      ans+=count/2;
      count=1;
    }
  }
  ans+=count/2;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = INF;

void solve(){
	vector<LL> accum(N,A[0]);
	for(int i=1;i<N;i++) accum[i] = accum[i-1] + A[i];

	//切れ込み3箇所のうち、真ん中を決めうち
	//インデックスi番目の直後に入れることを想定
	for(int middle=1;middle<=N-3;middle++){
		auto search = [&](int left_index,int right_index){
			LL left = left_index;
			LL right = right_index-1;
			while(left+1<right){
				LL center = (left+right)/2LL;
				LL leftside = accum[center] - ((left_index==0)?0:accum[left_index-1]);
				LL rightside = accum[right_index] - accum[center];
				if(leftside==rightside) return center;
				if(leftside>rightside) right = center;
				if(leftside<rightside) left = center;
			}
			LL left_diff,right_diff;
			{
				LL leftside = accum[left] - ((left_index==0)?0:accum[left_index-1]);
				LL rightside = accum[right_index] - accum[left];
				left_diff = abs(rightside-leftside);
			}
			{
				LL leftside = accum[right] - ((left_index==0)?0:accum[left_index-1]);
				LL rightside = accum[right_index] - accum[right];
				right_diff = abs(rightside-leftside);
			}
			return (left_diff<right_diff)?left:right;
		};
		LL left = search(0,middle);
		LL right = search(middle+1,N-1);

		LL P = accum[left];
		LL Q = accum[middle] - accum[left];
		LL R = accum[right] - accum[middle];
		LL S = accum[N-1] - accum[right];
		LL cand = max(max(P,Q),max(R,S)) - min(min(P,Q),min(R,S));
		ans = min(ans,cand);
	}
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

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

Measured memory_bytes: 6012
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

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

	for(int i = 0; i + 3 <= n; i++) {
		if(uno[i] == dos[i] && uno[i + 1] == dos[i + 1] && uno[i + 2] == dos[i + 2]) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

}



Measured memory_bytes: 3664
#include <iostream>
#include <cmath>

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	int ax[n];
 	float sum = 0.0;
	for (int i = 0; i < n; i++) {
		cin >> ax[i];
		sum += ax[i];
	}
	int avg = round(sum / n);
	int cost = 0;
	for (int i = 0; i < n; i++) {
		if (ax[i] != avg) {
			cost += pow(ax[i] - avg, 2);
		}
	}
	cout << cost << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=555;
int a[N*N],d[N*N],f[N*N];
int vis[N][N];
int n,m,k,tot;
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};
void dfs(int x,int y,int z){
	z=z+(vis[x][y]^1);
	for (int i=0; i<4; i++){
		int p=x+dx[i],q=y+dy[i];
		if (p<1||p>n||q<1||q>n)	continue;
		if (d[(p-1)*n+q]>z){
			d[(p-1)*n+q]=z;
			dfs(p,q,z);
		}
	}
}
int main(){
    scanf("%d",&n);
    for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
			d[(i-1)*n+j]=min(min(i-1,n-i),min(j-1,n-j));
    for (int i=1; i<=n*n; i++)
		scanf("%d",&a[i]);
	int ans=0;
	for (int i=1; i<=n*n; i++){
		ans=ans+d[a[i]];
		int x=(a[i]-1)/n+1;
		int y=a[i]-(x-1)*n;
		vis[x][y]=1;
		dfs(x,y,d[a[i]]);
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 24032
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int N;
string S;


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

	cin >> N >> S;
	int cnt = 0;
	REP(i,N){
		if(S[i] == 'R'){
			cnt++;
		}
	}

	if(cnt > N / 2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;
    vector<vector<vector<int>>> dp(n, vector<vector<int>>(t + 1, vector<int>(2, INT_MIN)));
    int ans = INT_MIN;
    rep(i, n) {
        if (t >= ab[i].first) dp[i][ab[i].first][0] = ab[i].second;
        dp[i][1][1] = ab[i].second;
        if (i == 0) continue;
        rep(ii, t + 1) {
            dp[i][ii][0] = max(dp[i][ii][0], dp[i - 1][ii][0]);
            ans = max(ans, dp[i][ii][0]);
            dp[i][ii][1] = max(dp[i][ii][1], dp[i - 1][ii][1]);
            ans = max(ans, dp[i][ii][1]);
            if (ii == 0) continue;
            dp[i][ii][1] = max(dp[i][ii][1], dp[i - 1][ii - 1][0] + ab[i].second);
            ans = max(ans, dp[i][ii][1]);
            if (ii < ab[i].first) continue;
            dp[i][ii][0] = max(dp[i][ii][0], dp[i - 1][ii - ab[i].first][0] + ab[i].second);
            ans = max(ans, dp[i][ii][0]);
            dp[i][ii][1] = max(dp[i][ii][1], dp[i - 1][ii - ab[i].first][1] + ab[i].second);
            ans = max(ans, dp[i][ii][1]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 492928
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//----------------------------------------------------------------

int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;
    char tmp;
    bool flag = false;
    for (int i = 0; i < k; i++)
    {
        if (s.at(i) != '1')
        {
            tmp = s.at(i);
            flag = true;
            break;
        }
    }
    if (flag)
    {
        cout << tmp << endl;
    }
    else
    {
        cout << "1" << endl;
    }
}

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

int main(void){
	int n;
	while(cin >> n){
		int currency[]={500,100,50,10,5,1};
		int count = 0;
		int pay = 1000 - n;
		if(n==0) break;
		for(int i=0;i<6;++i){
			if(pay/currency[i]>0) count+=pay/currency[i];
			pay%=currency[i];
		}
		cout << count << "\n";
	}
	return 0;
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    int ans = 0, maxi = 0;
    for(int i=0;i<n;++i){
        int h;
        cin >> h;
        if(h >= maxi){
            maxi = h;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
struct segTree{
  int n;
  vector<int> node;

  void init(int x){
    n = 1;
    while(n < x) n *= 2;
    node.resize(n*2-1,INT_MAX);
  }

  void update(int i, int x){
    i += n-1;
    node[i] = x;
    while(i > 0){
      i = (i-1)/2;
      node[i] = min(node[i*2 +1],node[i*2+2]);
    }
  }

  int getMin(int x, int y, int k=0, int l=0, int r=-1){
    if(r < 0) r = n;
    if(r<=x || l>=y) return INT_MAX;
    if(x<=l && r<=y) return node[k];

    int vl = getMin(x, y, 2*k+1, l, (l+r)/2);
    int vr = getMin(x, y, 2*k+2, (l+r)/2, r);
    return min(vl,vr);
  }
};
int main(){
  int n,q;
  cin >> n >> q;
  segTree t;
  t.init(n);
  //cout << "nodeSize: " << t.node.size() << endl;
  rep(i,q){
    int cmd;
    cin >> cmd;
    if(cmd == 0){
      int i,x;
      cin >> i >> x;
      t.update(i,x);
    }else{
      int x,y;
      cin >> x >> y;
      cout << t.getMin(x,y+1) << endl;
    }
    // for(int x: t.node) cout << x << ' ';
    // cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3888
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return None
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if __name__ == "__main__":
    N = int(input())
    A = factorization(N)
    cnt = 0
    if A:
        for a in A:
            b = a[1]
            c = 1
            d = 0
            while(c <= b):
                d += 1
                c += d+1
            cnt += d
    print(cnt)

Measured memory_bytes: 63348
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<cstring>
#include <cstdio>
#include<cmath>

typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main ()
{
    int m,d,f1,f2;
    cin>>m>>d>>f1>>f2;

    if (m==1 && d==31)
        cout<<"1"<<endl;

    else if (m==2 && d==28)
        cout<<"1"<<endl;

    else if (m==3 && d==31)
        cout<<"1"<<endl;

    else if (m==4 && d==30)
        cout<<"1"<<endl;

    else if (m==5 && d==31)
        cout<<"1"<<endl;


    else if (m==6 && d==30)
        cout<<"1"<<endl;


    else if (m==7 && d==31)
        cout<<"1"<<endl;


    else if (m==8 && d==31)
        cout<<"1"<<endl;


    else if (m==9 && d==30)
        cout<<"1"<<endl;


    else if (m==10 && d==31)
        cout<<"1"<<endl;

    else if (m==11 && d==30)
        cout<<"1"<<endl;

    else if (m==12 && d==31)
        cout<<"1"<<endl;

     else cout<<"0"<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;

namespace IO {
  static const int SZ = 1 << 20;
  static FILE *fin = stdin, *fout = stdout;
  static char ibuf[SZ], *is = ibuf, *it = ibuf;
  static char obuf[SZ], *os = obuf, *ot = obuf + SZ;

  inline char nextChar() {
    if (is == it) {
      it = (is = ibuf) + fread(ibuf, sizeof(char), SZ, fin);
      if (is == it)
        return EOF;
    }
    return *is++;
  }
  template <typename T>
  inline void readInt(T &x) {
    x = 0;
    T flag(1);
    char ch;
    for (ch = nextChar(); isspace(ch); ch = nextChar())
      ;
    if (ch == '-')
      ch = nextChar(), flag = -flag;
    for (; isdigit(ch); ch = nextChar())
      x = x * 10 + ch - '0';
    x *= flag;
  }
  inline void readCh(char &now) {
    for (now = nextChar(); isspace(now); now = nextChar())
      ;
  }

  inline void flushBuffer() {
    fwrite(obuf, sizeof(char), os - obuf, fout);
    os = obuf;
  }
  inline void printChar(char ch) {
    if (os == ot)
      flushBuffer();
    *os++ = ch;
  }
  template <typename T>
  inline void printInt(T x) {
    static int dig[20], cnt;
    if (os + 20 > ot)
      flushBuffer();
    if (x < 0)
      *os++ = '-', x = -x;
    cnt = 0;
    do {
      dig[++cnt] = x % 10;
      x /= 10;
    } while (x);
    for (int i = cnt; i > 0; --i)
      *os++ = dig[i] + '0';
  }
}

using namespace IO;

const int N = 1e5 + 5;

int n, a[N];
map<int, bool> mp;

int main() {
#ifdef LOCAL_DEBUG
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  readInt(n);
  for (int i = 1; i <= n; ++i) {
    int p;
    readInt(p);
    if (mp[p])
      mp[p] = false;
    else mp[p] = true;
  }
  int ans = 0;
  for (map<int, bool>::iterator it = mp.begin(); it != mp.end(); ++it) {
    if (it->second)
      ++ans;
  }
  printInt(ans);
  printChar('\n');
  flushBuffer();
  return 0;
}

Measured memory_bytes: 5888
import java.util.*;

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

	int n = sc.nextInt();

	while(n!=0){
	    String str = sc.next();
	    char[] c = str.toCharArray();

	    int[] aa = new int[n];
	    int[] bb = new int[n];
	    for(int i=0; i<n; i++){
		aa[i] = sc.nextInt();
		bb[i] = sc.nextInt();
	    }

	    for(int i=n-1; i>=0; i--){
		int a = aa[i];
		int b = bb[i]; 

		int diff = b-a;
		//if(c[a-1]+diff>'z'){c[a-1] = (char)(c[a-1]+diff-26);}
		//else {c[a-1] = (char)(c[a-1]+diff);}
		c[a-1] = (char)((c[a-1]-'a'+diff)%26 + 'a');

		//if(c[b-1]+diff>'z'){c[b-1] = (char)(c[b-1]+diff-26);}
		//else {c[b-1] = (char)(c[b-1]+diff);}
		c[b-1] = (char)((c[b-1]-'a'+diff)%26 + 'a');

		char tmp = c[a-1];
		c[a-1] = c[b-1];
		c[b-1] = tmp;

	    }
	    System.out.println(new String(c));
	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 12000
#include<stdio.h>
int main()
{
    int a,digit,flag=0;
    scanf("%d",&a);
    for(; a!=0;)
    {
        digit=a%10;
        if (digit==7)
        {
            flag=1;
            break;
        }
        a=a/10;
    }
    if (flag==1)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 1728
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
int mul[114514];int di[114514];
int fact(int x,int y){
    if(y==1)return x;
    else if(y%2==0)return fact(x*x%mod,y/2);
    else return fact(x*x%mod,y/2)*x%mod;
}
void init(){
    mul[0]=1;
    rep(i,1,114514)mul[i]=mul[i-1]*i%mod;
    di[114513]=fact(mul[114513],mod-2);
    for(int i=114512;i>=0;i--)di[i]=di[i+1]*(i+1)%mod;
}

int C(int n,int t){
    return mul[n]*di[t]%mod*di[n-t]%mod;
}
//終わり,nHt（重複も考える奴）=n+t-1Ctなので適宜調整
signed main(){
    int n,m;cin>>n>>m;
    int mm=m;
    vector<int> num;
    for(int i=2;i*i<=mm;i++){
        int cnt=0;
        while(m%i==0){
            cnt++;m/=i;
        }
        if(cnt)num.push_back(cnt);
    }init();
    if(m!=1)num.push_back(1);
    int ans=1;
    rep(i,0,num.size()){
        //cout<<num[i]<<" ";
      ans=ans*C(n+num[i]-1,num[i])%mod;
    }
    cout<<ans<<endl;return 0;
}


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A + B < C + D) {
		cout << "Right" << endl;
	}
	else if (A + B > C + D){
		cout << "Left" << endl;
	}
	else{
		cout << "Balanced" << endl;
	}
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args)throws IOException {
		FastIO sc = new FastIO(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n= sc.nextInt();
		long arr[] = new long[n];
		for(int i=0; i<n; ++i) {
			arr[i] = sc.nextLong();
		}
		Arrays.sort(arr);
		long ans = 0;
		int left = n-1;
		for(int i=n-1; i>=0; --i) {
			int num = i==n-1 ? 1 : 2;
			num = Math.min(num, left);
			ans+=num*arr[i];
			left-=num;
		}
		System.out.println(ans);
		out.close();
	}
	static class FastIO {
		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;
		public FastIO(String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}
		public FastIO(InputStream is) throws IOException {
			dis = is;
		}
		int nextInt() throws IOException {
			int ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
		long nextLong() throws IOException {
			long ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
			return (negative) ? -ret : ret;
		}
		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}
		String next() throws IOException {
			StringBuffer ret = new StringBuffer();
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}
 
			return ret.toString();
		}
	}
}


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

int main() {
  int N,M,ans=0;
  cin >> N;
  M = N;
  while (M > 10){
    ans += M % 10;
    M /= 10;
  }
  ans += M;
  if (N % ans == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

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


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;


int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    std::vector<int64_t> balls(N, 1);

    std::set<int64_t> reds;
    reds.insert(0);

    for (decltype(M) i = 0; i < M; ++i) {
        int64_t x, y;
        std::cin >> x >> y;
        x--;
        y--;

        balls[x]--;
        balls[y]++;

        if (reds.count(x) > 0) {
            reds.insert(y);
        }

        if (balls[x] == 0) {
            reds.erase(x);
        }
    }

    std::cout << reds.size() << std::endl;

    return 0;
}


Measured memory_bytes: 5760
n = int(input())
a_list = list(map(int,input().split()))
ans = 10**10
sum_of_list = sum(a_list)
sum_list = []
sum_list.append(a_list[0])
for i in range(1,n):
    sum_list.append(sum_list[i-1]+a_list[i]) 
for i in range(0,n-1):
    ans = min(ans, abs(sum_of_list - 2*sum_list[i]))
print(ans)

Measured memory_bytes: 24824
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N (1000000000+7)


int main(void) {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)cout << "YES" << endl;
	else cout << "NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<ll>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll INF = 1e6;

void solve()
{
    ll n, a, b;
    cin>>n>>a>>b;
    if(a==0)
    {
        cout<<0;
    }
    else
    {
        ll ans=0;
        if(n<=a)
            ans=n;
        else if(n>a &&n<a+b)
            ans=a;
        else
        {
            ans= a*(n/(a+b));
            n=n%(a+b);
            if(n<=a)
            ans+=n;
            //cout<<ans<<endl;
            if(n>a)
                ans+=a;
        }
        cout<<ans;
    }
}

 
int main()
{
    SPEED;
    ll t = 1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 3668
N = int(input())

A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 1:
    ans = B[N // 2] - A[N // 2] + 1
    print (ans)
else:
    a = (A[N // 2 - 1] + A[N // 2])
    b = (B[N // 2 - 1] + B[N // 2])
    print (b - a + 1)

Measured memory_bytes: 25436
#include <iostream>
#include <functional>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    sort(d,d+n);
    int count = n/2;
    int ans = d[count]-d[count-1];
    cout<<ans<<endl;
}


Measured memory_bytes: 3980
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

int main(){
    int N,M,Q;cin>>N>>M>>Q;
    vector<int> A(N,1),a(Q),b(Q),c(Q),d(Q);
    A[N-1] = 0;
    for(int i=0;i<Q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    int max = 0;
    do{
        A[N-1]++;
        for(int i=N-1;i>=1;i--){
            if(A[i]==M+1){
                A[i-1]++;
                for(int j=i;j<N;j++){
                    A[j] = A[i-1];
                }
            }
        }
        int sum = 0;
        for(int i=0;i<Q;i++){
            if(A[b[i]-1]-A[a[i]-1]==c[i]){
                sum += d[i];
            }
        }
        if(sum>max) max = sum;
    }while(A[0]!=M);
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int memo[26] = { 0 };

	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++)
	{
		memo[(int)S[i] - 97]++;
	}

	for (int i = 0; i < 26; i++)
	{
		if (memo[i] % 2 == 1)
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
import collections
n = int(raw_input())
mod = ( 10 ** 9 ) + 7
def f(u):
	cu = collections.Counter()
	cur = 2
	while(u != 1):
		if u % cur == 0:
			while(u % cur == 0):
				cc[cur] +=1
				u/= cur
		cur +=1
	return cu
cc = collections.Counter()
for u in range(2, n + 1):
	cu = f(u)
	for k in cu: cc[k]+=cu[k]
ans = 1
for k in cc:
	ans *= (cc[k] + 1) 
	ans %= mod
print ans

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

void init(bool array[]){
	for(int i=0;i<250000;i++){
		array[i]=true;
	}
}

void eratos(bool array[]){
	for(int i=2;i*i<250000;i++){
		if(array[i]==true){
			for(int j=0;i*(j+2)<250000;j++){
				array[i*(j+2)] = false;
			}
		}
	}
	array[1]=false;
}

int main(){
	bool array[250000];
	init(array);
	eratos(array);

	while(1){
		int n,cnt=0;
		cin >> n;
		if(n==0) break;
		for(int i=n+1;i<=n*2;i++){
			if(array[i]==true){
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1404
n,q = [int(i) for i in input().split()]
s = input()
ca = []
cc = []
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    ca.append(i+1)
    cc.append(i+2)
    
import bisect
for i in range(q):
  l,r = [int(i) for i in input().split()]
  in_a = bisect.bisect_left(ca, l)
  in_c = bisect.bisect_right(cc, r)
  #print(in_a,in_c)
  print(in_c-in_a)

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here
#define sizes 100010
#define PI 3.14159265
ll fact[sizes];
ll inv[sizes];
ll invfact[sizes];
ll ncr(ll n,ll i)
{
    if(i>n)
        return 0;
  return (((fact[n]*invfact[i])%mod)*invfact[n-i])%mod;
}
void factorial()
{
  fact[0]=1;
  for (ll i = 1; i <= sizes-5; i++)
  fact[i]=(fact[i-1]*i)%mod;
}
void invfactorial()
{
    inv[0] = inv[1] = invfact[0]=1;
    for (ll i = 2; i <= sizes-5; i++)
        inv[i] = (inv[mod % i] * (mod - mod / i) )% mod;
    for (ll i = 1; i <=sizes -5; i++)
        invfact[i]=(invfact[i-1]*inv[i])%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    ll n,k,sum=0;
    cin>>n>>k;
    ll a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    factorial();
    invfactorial();
    // cout<<ncr(2,1)*a[3];
    for(ll i=k-1;i<n;i++)
    {
        sum=(sum+(ncr(i,k-1)*(a[i])))%mod;
        // cout<<sum<<"\n";
    }
    for(ll i=0;i<=n-k;i++)
    {
        sum=(sum-(ncr(n-i-1,k-1)*(a[i])))%mod;
        // cout<<sum<<"\n";
        sum=(sum+mod)%mod;
    }
    cout<<sum<<"\n";
  return 0;
 }

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

int main(){
    int n, q, x;
    while(cin >> n >> q, n+q){
        string name[n];
        int by[n], wy[n];
        for(int i = 0; i < n; i++)  cin >> name[i] >> by[i] >> wy[i];
        for(int i = 0; i < q; i++){
            cin >> x;
            int j;
            for(j = 0; j < n; j++){
                if(wy[j] >= x && x >= wy[j]-by[j]+1)    break;
            }

            if(j == n){
                cout << "Unknown" << endl;
            }else{
                cout << name[j] << " " << x - (wy[j]-by[j]) << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int cnt = 0;
  for (int i = 0; i < 100000; i++) {
   if (a%2 == 1 || b%2 == 1 || c%2 == 1) {
      cout << cnt << endl;
      break;
    }
    else if (a == b && b == c) {
      cout << -1 << endl;
      break;
    }
    
    else {
      int x = a;
      int y = b;
      int z = c;
      a = y/2 + z/2;
      b = z/2 + x/2;
      c = x/2 + y/2;
      cnt++;
    }
  }
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int cnt = 0;
    int max_ = 0;

    rep1(i,1,n){
        if(h[i]<=h[i-1]){
            cnt++;
            max_ = max(max_,cnt);
        }else{
            cnt = 0;
        }
    }

    cout << max_ << endl;
    return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, M, K;
  cin >> N >> M >> K;

  vll r_A(N + 1);
  r_A[0] = 0;
  rep(i, N) {
    ll a;
    cin >> a;
    r_A[i + 1] = r_A[i] + a;
  }

  vll r_B(M + 1);
  r_B[0] = 0;
  rep(i, M) {
    ll b;
    cin >> b;
    r_B[i + 1] = r_B[i] + b;
  }

  ll ans = 0;
  rep(i, N + 1) {
    ll t = r_A[i];
    if (t > K) continue;
    ll count = i;
    ll nokori = K - t;
    ll ub = upper_bound(ALL(r_B), nokori) - r_B.begin();
    count += ub - 1;
    ans = max(ans, count);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 6372
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
table = [[0 for _ in range(W)] for _ in range(H)]
def dfsW(n):
  global table
  l = -1
  r = -1
  i = 0
  while i < W:
    if S[n][i] == ".":
      if l == -1:
        l = i
      r = i
    else:
      if l != -1:
        for j in range(l, r + 1):
          table[n][j] += r - l + 1
      l = -1
      r = -1
    i += 1
  if l != -1:
    for j in range(l, r + 1):
      table[n][j] += r - l + 1


def dfsH(n):
  global table
  l = -1
  r = -1
  i = 0
  while i < H:
    if S[i][n] == ".":
      if l == -1:
        l = i
      r = i
    else:
      if l != -1:
        for j in range(l, r + 1):
          table[j][n] += r - l + 1
      l = -1
      r = -1
    i += 1
    
  if l != -1:
    for j in range(l, r + 1):
      table[j][n] += r - l + 1


for i in range(H):
  dfsW(i)
for i in range(W):
  dfsH(i)
print(max(map(max, table)) - 1)

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

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n:usize,
        a:[i64;n]
    }
    let mut min=1_000_000_000;
    let mut minus=0;
    let mut ans=0;
    for i in 0..n {
        if a[i]<0 {
            minus+=1;
        }
        min=std::cmp::min(min, a[i].abs());
        ans+=a[i].abs();
    }
    if minus%2==1 {
        ans -= 2*min;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
 
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n;
  vl a;
  vl b;
  cin >> n;
  for(int i = 0; i < n; i++){
    ll x,y;
    cin >> x;
    cin >> y;
    a.push_back(x);
    b.push_back(y);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  
  ll range = b[n-1] - a[0];
  if(n%2 == 1){
    ll middle = (n-1)/2;
    printf("%lld", b[middle] - a[middle] + 1);
  }
  if(n%2 == 0){
    ll middle_h = n/2;
    ll middle_l = n/2 - 1;
    printf("%lld", ((b[middle_h] + b[middle_l]) - (a[middle_h] + a[middle_l]) + 1));
  }
  
  
 return 0;
}

Measured memory_bytes: 6572
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    cnt = 0
    for i in range(1, n + 1):
        for j in range(1 + i, n + 1):
            for k in range(1 + j, n + 1):
                if i + j + k == x:
                    cnt += 1
    print(cnt)



Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

using namespace std;

int main()
{

    int H, A;

    cin >> H >> A;

    if (H % A == 0)
    {
        cout << H / A;
    }
    else
    {
        cout << H / A + 1;
    }
    return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    long ans;
    foreach (d; 1 .. N)
    {
        long s_now;
        foreach (s; 0 .. N - d)
        {
            if (s + d < N && s < s_now + d && S[s] == S[s + d])
            {
                // writeln(S[s_now .. s_now + d]);
                ans = ans.max(s - s_now + 1);
            }
            else
            {
                s_now = s + 1;
            }
        }
    }
    writeln(ans);
}


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

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

    vector<int> D(N);
    for (int i = 0; i < N; i++){
        cin >> D.at(i);
    }

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

    int X = 1;
    for (int j = 1; j < N; j++){
        if (D.at(j) > D.at(j -1)){
            X++;
        }
    }

    cout << X << endl;
    
    
}

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

int main() {
  int Nb, Nr, base;
  base=0;
  cin >> Nb;
  vector<string> vec_blue(Nb);
  for (int i=0; i<Nb; i++) {
    cin >> vec_blue.at(i);
  }
  
  cin >> Nr;
  vector<string> vec_red(Nr);
  for (int i=0; i<Nr; i++) {
    cin >> vec_red.at(i);
  }
  
  vector<string> vec_t(Nb,"~");
  
  for (int i=0; i<Nb; i++) {
    int count=0;
    for (int j=0; j<Nb; j++) {
      if (vec_blue.at(i)==vec_blue.at(j)) {
        count++;
      }
    }
    for (int j=0; j<Nr; j++) {
      if (vec_blue.at(i)==vec_red.at(j)) {
        count--;
      }
    }
    base=max(count,base);
  }
  cout << base << endl;
}
      


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N;
	int a = 0, w = 0, t = 0, r = 0;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		char S[128];
		if (scanf("%127s", S) != 1) return 1;
		switch (S[0]) {
			case 'A': a++; break;
			case 'W': w++; break;
			case 'T': t++; break;
			case 'R': r++; break;
		}
	}
	printf("AC x %d\n", a);
	printf("WA x %d\n",w);
	printf("TLE x %d\n", t);
	printf("RE x %d\n", r);
	return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

vl a;
void dfs(ll n,ll x){
    if(n>=x){
        a.pb(x);
        x*=10;
        if(n>=x+3)dfs(n,x+3);
        if(n>=x+5)dfs(n,x+5);
        if(n>=x+7)dfs(n,x+7);
    }
    return;
}


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

    ll n;
    cin >> n;
    dfs(n,ll(0));
    ll cnt = 0;
    
    rep(i,a.size()){
        vi mp(10,0);
        string tmp = to_string(a[i]);
        rep(j,tmp.size()){
            mp[tmp[j]-'0']++;
        }
        if(mp[3]!=0 &&mp[5]!=0 &&mp[7]!=0){cnt++;}

    }
    cout << cnt << endl;
    return 0;
}
    

Measured memory_bytes: 640
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

S = sys.stdin.readline().rstrip()
print(S.count('1'))


Measured memory_bytes: 21328