akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vpii = vector<pii>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
int main() {
    int m, n;
    cin >> m >> n;
    vector<string> map(m);
    for (auto &a : map)cin >> a;
    bool f = 1;
    int score = 0;
    while (f) {
        f = 0;
        rep(i, m)rep(j, n) {
            if (map[i][j] != '.')continue;
            vector<pair<char,string::iterator>> buf;
            rep(k, 4) {
                int x = j, y = i;
                while (x >= 0 && x < n&&y>=0 && y < m&&map[y][x] == '.')x += dx[k], y += dy[k];
                if (x >= 0 && x < n&&y>=0 && y < m)buf.push_back(make_pair(map[y][x],map[y].begin()+x));
            }
            sort(ALL(buf), [](pair<char, string::iterator> a, pair<char, string::iterator> b) {return a.first < b.first; });
            if (buf.size() < 2)continue;
            rep1(i, buf.size()-1) {
                if (buf[i].first == buf[i - 1].first) {
                    *(buf[i].second) = *(buf[i - 1].second) = '.';
                    score += 2;
                    f = 1;
                }
            }
        }
    }
    cout << score << endl;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int Mod = 1e9 + 7;

#define pii pair<int, int>
#define fi first
#define se second
#define N 100100 

int n, m, a[N], b[N], f[N], sum[N];
int lim, sh[N];
pii p[N];

inline void add(int pos, int val) {
    while (pos <= lim) {
        sum[pos] = (sum[pos] + val) % Mod;
        pos += pos & (-pos);
    }
}

inline int ask(int pos) {
    int res = 0;
    while (pos) {
        res = (res + sum[pos]) % Mod;
        pos -= pos & (-pos);
    }
    return res;
}

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= m; ++i) scanf("%d", b + i);

    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int pos = upper_bound(b + 1, b + m + 1, a[i]) - b;
        if (pos > m || pos <= 1) continue;
        p[++cnt] = make_pair(a[i] - b[pos - 1], (sh[++lim] = (b[pos] - a[i])));
    }

    sort(sh + 1, sh + lim + 1);
    lim = unique(sh + 1, sh + lim + 1) - (sh + 1);

    sort(p + 1, p + cnt + 1);

    int now = 1;
    for (int i = 2; i <= cnt; ++i)
        if (p[i] != p[i - 1]) p[++now] = p[i];
    cnt = now;

//    for (int i = 1; i <= cnt; ++i)
//        cout << p[i].fi << " " << p[i].se << endl;

    for (int l = 1, r; l <= cnt; l = r + 1) {
        for (r = l; r < cnt && p[r + 1].fi == p[l].fi; ++r);
        for (int i = l; i <= r; ++i) {
            p[i].se = lower_bound(sh + 1, sh + lim + 1, p[i].se) - sh;
            f[i] = 1 + ask(p[i].se - 1);
        }
        for (int i = l; i <= r; ++i)
            add(p[i].se, f[i]);
    }

    cout << ask(lim) + 1 << endl;

    return 0;
}


Measured memory_bytes: 2688
$<.readlines.each do |l|
  a, b, c, d, e, f = l.split.map(&:to_i)
  r = a * e - b * d
  x = (c * e - b * f) / r.to_f
  y = (a * f - c * d) / r.to_f
  x = x.abs if x == 0
  y = y.abs if y == 0
  printf("%.3f %.3f\n", x.round(4), y.round(4))
end


Measured memory_bytes: 6924
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int N,M;
vector<vector<bool>> G(10, vector<bool>(10,false));
vector<bool> visited(10, false);

int dfs(int v, int N, vector<bool> visited){
  bool all_visited = true;
  for(int i=0; i<N; i++){
    if(!visited[i]){
      all_visited = false;
    }
  }
  if(all_visited){
    return 1;
  }
  int ret=0;
  for(int i=0; i<N; i++){
    if(!G[v][i]) continue;
    if(visited[i]) continue;

    visited[i] = true;
    ret += dfs(i, N, visited);
    visited[i] = false;
  }
  return ret;
}


int main(){
  cin >> N >> M;
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    G[a-1][b-1] = true;
    G[b-1][a-1] = true;
  }
  visited[0] = true;
  cout << dfs(0,N,visited) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  if (n != 0 && m != 0) {
    cout << m * (m - 1) / 2 + n * (n - 1) / 2 << endl;
  } else if (n == 0 && m != 0) {
    cout << m * (m - 1) / 2 << endl;
  } else {
    cout << n * (n - 1) / 2 << endl;
  }
  return 0;
}


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

int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<1000;i++){
        string sum ="";
        if(i<10){
            sum += "00";
        }else if(i<100){
            sum += "0";
        }
        
        sum += to_string(i);
        
        int cu = 0;
        
        for(int j=0;j<n;j++){
            if(sum[cu] == s[j]){
                cu++;
            }
            if(cu == 3) break;
        }
        
        if(cu == 3) ans++;
    }
    
    
    cout << ans << endl;
}


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

const long long MOD=1000000007;

int main(){
  int N,K; cin >> N >> K;
  vector<long long> A(N);
  int Nplus=0,Nzero=0,Nminus=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i]>0) Nplus++;
    else if(A[i]==0) Nzero++;
    else Nminus++;
  }
  vector<long long> Aplus(Nplus),Aminus(Nminus);
  int tp=0,tm=0;
  for(int i=0; i<N; i++){
    if(A[i]>0){
      Aplus[tp]=A[i]; tp++;
    }else if(A[i]<0){
      Aminus[tm]=-A[i];
      tm++;
    }
  }
  int count=0,pcount=0,mcount=0;
  long long result=1;
  if(Nplus>=K || K-min(K/2,Nminus/2)*2<=Nplus){
    
    //+にできる
    //-から2個ずつなら持ってきてよい
    sort(Aplus.begin(),Aplus.end(),greater<long long>());
    sort(Aminus.begin(),Aminus.end(),greater<long long>());
    
    while(count<K){
      if(count+1==K){
        result*=Aplus[pcount]; result%=MOD;
        pcount++; count++;
      }else{
        if(pcount<Nplus-1 && mcount<Nminus-1){
          long long ptemp,mtemp;
          ptemp=Aplus[pcount]*Aplus[pcount+1];
          mtemp=Aminus[mcount]*Aminus[mcount+1];
          if(ptemp>mtemp){
            result*=Aplus[pcount]; result%=MOD;
            pcount++; count++;
          }else{
            result*=Aminus[mcount]; result%=MOD;
            mcount++; count++;
            result*=Aminus[mcount]; result%=MOD;
            mcount++; count++;
          }
        }else if(mcount>=Nminus-1){
          result*=Aplus[pcount]; result%=MOD;
          pcount++; count++;
        }else{
          result*=Aminus[mcount]; result%=MOD;
          mcount++; count++;
          result*=Aminus[mcount]; result%=MOD;
          mcount++; count++;
        }
      }
    }
    
  }else if(Nzero>0){
    
    //+にはできないが0にできるのでするしかない
    result=0;
    
  }else{
    
    //-にしかならない
    //絶対値最小を目指す
    vector<long long> Aabs(Nplus+Nminus);
    for(int i=0; i<Nplus; i++){
      Aabs[i]=Aplus[i];
    }
    for(int i=0; i<Nminus; i++){
      Aabs[i+Nplus]=Aminus[i];
    }
    sort(Aabs.begin(),Aabs.end());
    for(int i=0; i<K; i++){
      result*=Aabs[i];
      result%=MOD;
    }
    result=(MOD-result)%MOD;
    
  }
  
  cout << result << endl;
}

Measured memory_bytes: 7928
from collections import deque

n, x, y = map(int, input().split())

inf = 100100100
x -= 1
y -= 1

ans = [0] * n

for i in range(n):
    dist = [inf] * n
    queue = deque()
    queue.append(i)
    dist[i] = 0
    while queue:
        current = queue.popleft()
        d = dist[current]

        if current - 1 >= 0 and dist[current - 1] == inf:
            queue.append(current - 1)
            dist[current - 1] = d + 1
        if current + 1 < n and dist[current + 1] == inf:
            queue.append(current + 1)
            dist[current + 1] = d + 1
        if current == x and dist[y] == inf:
            queue.append(y)
            dist[y] = d + 1
        if current == y and dist[x] == inf:
            queue.append(x)
            dist[x] = d + 1

    for j in range(n):
        ans[dist[j]] += 1

for k in range(1, n):
    print(ans[k] // 2)


Measured memory_bytes: 49884
A = input()

alf = [
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'I',
    'J',
    'K',
    'L',
    'M',
    'N',
    'O',
    'P',
    'Q',
    'R',
    'S',
    'T',
    'U',
    'V',
    'W',
    'X',
    'Y',
    'Z',
]

if A in alf:
    print('A')
else:
    print('a')


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
int main(){
    string a, b;
    int cnt, mini=1e9;
    getline (cin, a), getline (cin, b);
    for (int i=0; i<=a.length()-b.length(); i++){
        cnt=0;
        for (int j=0; j<b.length(); j++){
            if (b[j]!=a[i+j]) cnt++;
        }
        mini=min(mini, cnt);
    }
    cout<<mini<<endl;
}

Measured memory_bytes: 3624
from sys import stdin

EPS = 1e-10

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.yb

    def __lt__(self, other):
        return self.x < other.x and self.y < other.yb

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    # usually cross operation return Vector but it returns scalor
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        self.p1 = p1
        self.p2 = p2

def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    if a.cross(b) > EPS:
        return 1
    elif a.cross(b) < -EPS:
        return -1
    elif a.dot(b) < -EPS:
        return 2
    elif a.norm() < b.norm():
        return -2
    else:
        return 0

def read_and_print_results(p0, p1, n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p2 = Vector(int(line[0]), int(line[1]))
        result = ccw(p0, p1, p2)
        if result == 1:
            print('COUNTER_CLOCKWISE')
        elif result == -1:
            print('CLOCKWISE')
        elif result == 2:
            print('ONLINE_BACK')
        elif result == -2:
            print('ONLINE_FRONT')
        elif result == 0:
            print('ON_SEGMENT')

x0, y0, x1, y1 = [int(i) for i in input().split()]
p0 = Point(x0, y0)
p1 = Point(x1, y1)
n = int(input())
read_and_print_results(p0, p1, n)


Measured memory_bytes: 5808
def main():
    S = input()
    N = len(S)
    A = [ 0 for _ in range(N+1)]

    for i in range(N):
        if S[i] == '<':
            A[i+1] = A[i]+1

    for i in reversed(range(N)):
        if S[i] == '>':
            A[i] = max(A[i+1]+1, A[i])

    print(sum(A))


if __name__ == '__main__':
    main()


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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
  string s;
  std::cin >> s;
  int dp,dg,tp,tg;
  dp=s.size()/2;
  dg=s.size()-dp;
  tp=tg=0;
  rep(i,s.size()){
    if(s[i]=='g') tg++;
    else tp++;
  }
  std::cout << (dp-tp) << std::endl;
}


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

int main() {
  long long a, b, n;
  cin >> a >> b;
  if(a > b) swap(a, b);
  n = a;
  while(1) {
    if(n % b == 0) {cout << n << endl; return 0; }
    n += a;
  }
}


Measured memory_bytes: 256
use std::cmp::{max,min};
macro_rules! string2tuple {
    ($l:ident, ($($t:ty),*)) => {{
        let mut ws = $l.split_whitespace();
        (
            $(ws.next().unwrap().parse::<$t>().unwrap(),)*
        )
    }}
}
fn solve(nm: &str) -> i64 {
    let (n,m) = string2tuple!(nm,(i64,i64));
    min(n,m/2)+max(0,(m-n*2)/4)
}
fn main() {
    loop {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right();
        if s=="" { break; }
        println!("{}",solve(&s));
    }
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		char[][] field = new char[h][];
		for (int i = 0; i < h; i++) {
		    field[i] = sc.next().toCharArray();
		}
		int ans = 0;
		for (int a = 0; a < (1 << h); a++) {
		    for (int b = 0; b < (1 << w); b++) {
		        int count = 0;
		        for (int i = 0; i < h; i++) {
		            if ((a & (1 << i)) == 0) {
		                continue;
		            }
		            for (int j = 0; j < w; j++) {
		                if ((b & (1 << j)) != 0 && field[i][j] == '#') {
		                    count++;
		                } 
		            }
		        }
		        if (count == k) {
		            ans++;
		        }
		    }
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35776
while 1:
    try:
        count = 0
        n = int(input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a + b + c + d == n:
                            count += 1
        print(count)
    except:
        break



Measured memory_bytes: 5588
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Measured memory_bytes: 100872
n=[]
while (a=gets)!=nil
n<< a.split.map(&:to_i)
end
n.each{|e|
exit if e[0]==e[1]&&e[0]==0
now=1
loop do
case now
when 1;puts "#"*e[1];now+=1
when e[0];puts "#"*e[1];break
else;_= Array.new(e[1]-2,".").join;puts "#"+_+"#";now+=1
end
end
puts
}


Measured memory_bytes: 7300
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())-1
    alp = "abcdefghijklmnopqrstuvwxyz"
    s = []
    while n >= 0:
        s.append(alp[n%26])
        n = (n//26-1)
    print("".join(s[::-1]))

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 68728
M=10**6
p=[1]*M
p[0]=p[1]=0
for i in range(2,10**5+1):
    if p[i]:
        for j in range(i*i,M,i):
            p[j]=0
C=[0]*M
for i in range(2,M):
    if p[i] and p[(i+1)//2]:
        C[i]=C[i-1]+1
    else:
        C[i]=C[i-1]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(C[r]-C[l-1])

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e12

int const N = 1e6;

int n, k;

ll dp[N];
ll h[N];

ll Jump_frog(int i)
{
    if (i >= n)
        return 0; //Essa é a condição ótima de parada

    if (dp[i] != -1)
        return dp[i];

    ll best_jump = inf;

    for (int j = 1; j <= k && (i + j) <= n; j++) //A quantidade de pulos possíveis
        best_jump = min( best_jump , (Jump_frog(i+j) + abs(h[i+j] - h[i]) ) );

    return dp[i] = best_jump;
}

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

    memset(dp, -1, sizeof dp);

    for (int i = 1; i <= n; i++)
        cin >> h[i];

    cout << Jump_frog(1) << endl;

    return 0;
}


Measured memory_bytes: 18424
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end(), greater<int>());

  if (S < T)  cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3612
n = gets.to_i
w = gets.split.map(&:to_i)

left = [w.first]
1.upto(n - 2).each {|i|
    left.push(left.last + w[i])
}

right = [w.last]
(n - 2).downto(1).each {|i|
    right.push(right.last + w[i])
}
right.reverse!

min = (left[0] - right[0]).abs
1.upto(n - 2).each {|i|
    abs = (left[i] - right[i]).abs
    if abs < min then
        min = abs
    end
}

puts min


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define int long long
#define ld long double
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int a, b;
  cin >> a >> b;
  if(a < 10 && b < 10){
    cout << a * b;
  }else{
    cout << -1;
  }
}

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

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

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut ans = 0;

    for _ in 0..n {
        a.push(read());
    }

    for i in 0..n {
        ans += a[i] - 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
from collections import deque

INF = float('inf')
H, W = map(int, input().split())
grid = [str(input()) for _ in range(H)]
d = [[-1] * W for _ in range(H)]
d[0][0] = 0
dh = [1, -1, 0, 0]
dw = [0, 0, 1, -1]
q = deque([[0, 0]])
while q:
    h, w = q.popleft()
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if 0 <= nh < H and 0 <= nw < W and d[nh][nw] < 0:
            if grid[nh][nw] == '#':
                d[nh][nw] = INF
            else:
                d[nh][nw] = d[h][w] + 1
                q.append([nh, nw])
if d[H-1][W-1] == -1:
    print(-1)
else:
    cnt = 0
    for i in range(H):
        cnt += grid[i].count('.')
    print(cnt - d[H-1][W-1] - 1)


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

//char型をint型へ変換
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}



int main(){
    string s;
    int seven;
    cin >> s;
    int n = s.size() -1;
    vector<int> a(n+1);
    vector<char> op(n);
    for (int i = 0; i < s.size(); i++){
        a.at(i) = ctoi(s.at(i));
    }
    //cout << a.at(1) << " " << a.at(2);
    
    for (int bit = 0; bit < (1<<n); bit++){
        seven = a.at(0);
        for (int i = 0; i < n; i++){
            if (bit & (1<<i)) {
                op.at(i) = '+';
                seven += a.at(i+1);
            }
            else {
                op.at(i) = '-';
                seven -= a.at(i+1);
            }
        }
        
        if(seven == 7){
            cout << a.at(0) << op.at(0) << a.at(1) << op.at(1) << a.at(2) << op.at(2);
            cout << a.at(3) << "=7";
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
#define MP make_pair<int,int>
int q,a,v,score[1000001],top=-1;
pii P;
priority_queue<pii> Q;
int main(){
  scanf("%d%d",&q,&q);
  Q.push(MP(0,-1));
  while(q--){
    scanf("%d%d",&a,&v);
    score[a] += v;
    if(top==-1)top=a;
    if(top==a&&v>0){
      printf("%d %d\n",top,score[top]);
      Q.pop();
      Q.push(MP(score[a],-a));
      continue;
    }
    Q.push(MP(score[a],-a));
    while(true){
      P = Q.top();
      if(score[-P.second]!=P.first)Q.pop();
      else{
        printf("%d %d\n",-P.second,P.first);
        top = -P.second;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int M,D;
  cin>>M;
  cin>>D;
  int count=0;
    for(int i=20;i<=D;i++){
      int f=i%10;
      int s=i/10;
      if(f>1 && f*s<=M){
        count++;
      }
    }
  cout<<count;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int D[20],s[30];
vector<int> v;

void reset(){
    for(int i=0;i<30;i++) s[i]=0;
    for(int i=0;i<(int)v.size();i++){
        s[v[i]]++;
    }
    s[0]++;
    s[24]++;
}


int main(){
    int N,a,ans=0;
    cin>>N;

    for(int i=0;i<N;i++){
        cin>>a;
        D[a]++;
    }

    D[0]++;

    for(int i=0;i<=12;i++){
        if(i==0 && D[i]>=2 || i==12 && D[i]>=2 || D[i]>=3){
            cout<<0<<endl;
            return 0;
        }else if(D[i]==2){
            v.push_back(i); v.push_back(24-i);
            D[i]=0;
        }
    }

    reset();

    for(int bit=0;bit< (1<<13); bit++,reset()){
        for(int i=0;i<13;i++){
            if(D[i]==0) continue;
            if(bit>>i & 1){
                s[24-i]++;
            }else{
                s[i]++;
            }
        }
        int temp=0,ss=100;
        for(int i=1;i<=24;i++){
            if(s[i]){
                ss=min(i-temp,ss);
                temp=i;
            }
        }
        ans=max(ans,ss);
    }
    cout<<ans<<endl;
}

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

using namespace std;

int dp[100000];

int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(N), r(N);
    for(int i = 0; i < Q; i++){
        cin >> l[i] >> r[i];
    }
    
    bool flag = false;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(flag && S[i] == 'C'){
            cnt++;
            dp[i] = cnt;
            flag = false;
            continue;
        }
        
        if(S[i] == 'A'){
            flag = true;
        }
        else{
            flag = false;
        }
        dp[i] = cnt;
    }
    
    for(int i = 0; i < Q; i++){
        cout << dp[r[i] - 1] - dp[l[i] - 1] << endl;
    }
}

Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys
from itertools import chain
# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


def solve(A: int, B: str):
    B = int(B.replace('.', ''))
    ans = A * B
    return ans // 100

def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    A = int(next(tokens))  # type: int
    B = next(tokens)  # type: str
    answer = solve(A, B)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9064
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int X, Y, Z, K;
vector<long long int> v;
long long int A[1100], B[1100], C[1100];

bool check(long long int min_A){
    long long int cnt = 0;
    for(int i = 0; i < Z; i++){
        long long int rem = min_A - C[i];
        cnt += distance(lower_bound(v.begin(), v.end(), rem), v.end());
    }
    return cnt >= K;
}

long long int bin_search(long long int lef, long long int rig){
	long long int middle = (lef + rig) / 2;
	if(rig - lef <= 1){
        return lef;
	}
	if(check(middle)){
		lef = middle;
	}else{
		rig = middle;
	}
	return bin_search(lef, rig);
}

int main(){
    cin >> X >> Y >> Z >> K;
    for(int i = 0; i < X; i++){
        cin >> A[i];
    }
    for(int i = 0; i < Y; i++){
        cin >> B[i];
    }
    for(int i = 0; i < Z; i++){
        cin >> C[i];
    }
    for(int i = 0; i < X; i++){
        for(int j = 0; j < X; j++){
            v.push_back(A[i] + B[j]);
        }
    }
    sort(v.begin(), v.end());
    sort(A, A + X);
    sort(B, B + Y);
    sort(C, C + Z);
    long long int num = bin_search(1, 1e15);
    vector<long long int> ans;
    for(int i = X - 1; i >= 0; i--){
        for(int j = Y - 1; j >= 0; j--){
            for(int k = Z - 1; k >= 0; k--){
                if(A[i] + B[j] + C[k] <= num){
                    break;
                }
                ans.push_back(A[i] + B[j] + C[k]);
            }
        }
    }
    while(ans.size() < K){
        ans.push_back(num);
    }
    sort(ans.begin(), ans.end());
    for(int i = K - 1; i >= 0; i--){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10604
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
signed main() {
	int x;
	cin >> x;
	cout << x * x * x << endl;
	ggr
}



Measured memory_bytes: 3096
from sys import stdin
from math import ceil, floor
n, a, b = [int(x) for x in stdin.readline().rstrip().split()]
s = list(stdin.readline().rstrip())
c = a + b
d = 0
e = 0
for i in range(n):
    if d < c and s[i] == "a":
        print("Yes")
        d += 1
    elif d < c and e < b and s[i] == "b":
        print("Yes")
        d += 1
        e += 1
    else:
        print("No")

Measured memory_bytes: 9952
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

struct UnionFind{
	vector<int>par,size;
	int find(int x){
		return (par[x]==x?x:par[x]=find(par[x]));
	}
	bool merge(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		par[x]=y;
		size[y]+=size[x];
		return true;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	UnionFind(int x):size(x,1),par(x){
		iota(all(par),0);
	}
};
int N;
pair<P,int> V[200005];
set<P>st;
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N){
		cin>>V[i].first.first>>V[i].first.second;
		V[i].second=i;
	}
	sort(V,V+N);
	UnionFind uf(N);
	rep(i,N){
		int mn=V[i].first.second;
		for(auto it=st.begin();it!=st.end()&&it->first<V[i].first.second;){
			uf.merge(it->second,V[i].second);
			chmin(mn,it->first);
			it=st.erase(it);
		}
		st.insert({mn,V[i].second});
	}
	rep(i,N){
		cout<<uf.size[uf.find(i)]<<"\n";
	}
}

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

int main() {
  string l;
  cin>>l;
  ll a=1,b=2;
  for (int i=1; i<l.size(); i++) {
    if (l[i]=='1') {
      a=(a*3%1000000007+b)%1000000007;
      b=b*2%1000000007;
    }
    else {
      a=a*3%1000000007;
    }
  }
  cout<<(a+b)%1000000007<<endl;
  return 0;
}

Measured memory_bytes: 512
n, k = map(int, input().split())
x = list(map(int , input().split()))

#from bisect import bisect_left

#p0 = bisect_left(x, 0)
#x[p0] == 0
ans = 10 ** 10
for i in range(n-k+1):
    ans = min(ans, abs(x[i]) + abs(x[i+k-1] - x[i]))
    ans = min(ans, abs(x[i+k-1]) + abs(x[i+k-1] - x[i]))
    #print(i, i+k-1, ans)
print(ans)

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

int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans=0;
  for (int i=0;i<=a;i++){
    for (int j=0;j<=b;j++){
      for (int k=0;k<=c;k++){
        if (x==500*i+100*j+50*k){
          ans+=1;
          break;
        }
        if (x<500*i+100*j+50*k){
          break;
        }
      }
    }
  }
  cout << ans << endl;
 }


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

int main() {
  int N,Y,z,aaa=0;
  cin >> N >> Y;
  for(int x=0;x<=N;x++){
    for(int z=0;z<=N-x;z++){
      int y=N-x-z;
      if(5000*x-4000*z==Y-5000*N){
      	cout << x << " " << y << " " << z << endl;
        aaa=1;
        break;
      }
      if(aaa) break;
    }
  }if(!aaa)
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define R freopen("A.in","r",stdin);
#define W freopen("A.out","w",stdout);
const int N=305;
char s[N];
int k,d[N][N][N],n;
int dp(int i,int j,int x)
{
    if(i==j)return 1;
    if(i>j)return 0;
    int& ans=d[i][j][x];
    if(ans!=-1)return ans;
    if(s[i]==s[j])ans=dp(i+1,j-1,x)+2;
    else if(x)ans=max(max(dp(i,j-1,x),dp(i+1,j,x)),dp(i+1,j-1,x-1)+2);
         else ans=max(dp(i,j-1,x),dp(i+1,j,x));
    return ans;
}
int main()
{
    
    memset(d,-1,sizeof d);
    scanf("%s%d",s,&k);
    n=strlen(s);
    cout<<dp(0,n-1,k);
    return 0;
}


Measured memory_bytes: 111104
//Atcoder-2299-Card Eater
//Writer: InvisibleCyclist
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
	int n,val,ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&val);
		if(a[val]!=1){
			a[val]=1;
			ans++;
		}
	}
	printf("%d\n",ans-1+ans%2);
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	int f[1000001],n,a,b,i,j,t,ans;
	while(1){
		scanf("%d %d %d",&n,&a,&b);
		if(n==0&&a==0&&b==0){
			break;
		}
		for(i=1;i<=n;i++){
			f[i]=0;
		}
		f[0]=1;
		ans=0;
		for(i=1;i<=n;i++){
			if(i-a>=0&&f[i-a]==1){
				f[i]=1;
			}
			if(i-b>=0&&f[i-b]==1){
				f[i]=1;
			}
			if(f[i]!=1){
				ans++;
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  int year,month;
  cin >> s;
  month = (int)(s[5] - '0')*10 + (int)(s[6] - '0');
  if(month >= 5){
    cout << "TBD"<< endl;
  }else{
    cout << "Heisei" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string str;
	getline(cin,str);
	int l = str.length();
	int a = 0, b = 0;
	for (int i = 0; i < l; ++i)
	{
		if (i % 2 == 1)
			if (str[i] == '0')
				b++;
			else a++;
		else if (str[i] == '0')
			a++;
		else b++;
	}
	printf("%d\n", min(a,b));
}

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

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

fn main() {
    let n = read::<u8>();
    let s = read::<String>().chars().collect::<Vec<char>>();
    for &c in s.iter() {
        let d = ((c as u8 - b'A' + n) % 26 + b'A') as char;
        print!("{}", d)
    }
    println!("");
}


Measured memory_bytes: 2148
(defun hitachi-str-p (str)
  (let ((ans 0))
    (if (not (= 0 (rem (length str) 2)))
	nil
	(progn
	  (do ((n 0 (incf n 2)))
	      ((>= n (length str)))
	    (if (string= "hi" (subseq str n (+ n 2)))
		(incf ans)
		(progn
		  (setq ans 0)
		  (return))))
	  (if (= 0 ans)
	      nil
	      t)))))

(defun main ()
  (if (hitachi-str-p (read-line))
      (format t "Yes~%")
      (format t "No~%")))

(main)


Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int count=0,n=0,inp=0;
  cin>>n;
  for(int i=1;i<=n;i++){
  cin>>inp;
    if((i%2 == 1) && (inp%2 == 1)){
    count++;
    }
  }
  cout<<count<<'\n';
  return 0;
}

Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        char[] c = a.toCharArray();
        c[0] += (char)1;
        System.out.println(c);
        
    }
}


Measured memory_bytes: 35500
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int N,M;
    cin >> N >> M;
    int i,j,k,l;
    string a[N],b[M];
    for(i=0;i<N;i++){
      cin >> a[i];
    }
    for(j=0;j<M;j++){
      cin >> b[j];
    }
    int flag;
    for(i=0;i<=N-M;i++){
      for(j=0;j<=N-M;j++){
        flag=0;
        for(k=0;k<M;k++){
          for(l=0;l<M;l++){
            if(a[i+k][j+l]!=b[k][l]){
              flag=1;
            }
          }
        }
        if(flag==0){
          cout << "Yes";
          return 0;
        }
      }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i, n+1) cin >> a.at(i);
  vector<int> b(n);
  rep(i, n) cin >> b.at(i);
  ll ans = 0;
  rep(i, n){
    ans += min(b.at(i), a.at(i));
    b.at(i) -= a.at(i);
    if(b.at(i) > 0){
      ans += min(b.at(i), a.at(i+1));
      a.at(i+1) = max(0, a.at(i+1)-b.at(i));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3932
#include<stdio.h>
int main()
{
    int n,x,i,j,k,count;
    while(1)
    {
        scanf("%d %d",&n,&x);
        count=0;
        if(n==0 && x==0)
        {
            break;
        }
        for(i=1;i<n-1;i++)
        {
            for(j=i+1;j<n;j++)
            {
                for(k=j+1;k<n+1;k++)
                {
                    if(i+j+k==x)
                    {
                        count++;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}



Measured memory_bytes: 2072
#include <stdio.h>
using namespace std;

int main(){
    int n,x,count;
    while(true){
        scanf("%d %d",&n,&x);
        if(n==0&&x==0)break;
        count=0;
        for(int i=n;i>=3;i--)for(int j=i-1;j>=2;j--)for(int k=j-1;k>=1;k--)if(i+j+k==x)count++;
        printf("%d\n",count);
    }
}


Measured memory_bytes: 2600
D, G = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(D)]
plst = [0] * D
ans = 0
for i in range(D):
    ans += p[i][0]

def dfs(n):
    global ans
    if n == D:
        cnt = 0
        total = 0
        for i in range(D):
            if plst[i] == 0:
                continue
            elif plst[i] == 1:
                cnt += p[i][0]
                total += (100 * (i + 1) * p[i][0]) + p[i][1]
        if total < G:
            for j in range(D - 1, -1, -1):
                if plst[j] == 0:
                    for k in range(p[j][0] - 1):
                        total += (100 * (j + 1))
                        cnt += 1
                        if total >= G:
                            break
                    break
            if total >= G:
                ans = min(ans, cnt)
        else:
            ans = min(ans, cnt)
        return

    for i in range(2):
        plst[n] = i
        dfs(n + 1)
    return

dfs(0)
print(ans)

Measured memory_bytes: 3064
import copy
import sys
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
ans = 0
def dfs(start,path):
    next_path = copy.copy(path)
    global ans
    next_path.append(start)
    if len(next_path) == N:
        ans += 1
        return
    for i in edges[start]:
        if i not in next_path:
            dfs(i,next_path)
dfs(0,[])
print(ans)

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

int main()
{
  int n;
  cin >> n;
  int t[n];
  for(int i = 1; i <= n; i++) cin >> t[i];
  
  int m;
  cin >> m;
  int p[m+1],x[m+1];
  for(int i = 1; i <= m; i++) cin >> p[i] >> x[i];
  
  int ans[m+1] = {0};
  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= n; j++){
      if(j == p[i]){
        ans[i] += x[i];
      }else{
        ans[i] += t[j];
      }
    }
  }
  
  for(int i = 1; i <= m; i++){
    cout << ans[i] << endl;
  }
      
}

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main() {
  ll N;
  cin >> N;
  ll a;
  cin >> a;
  ll ans = a;
  for (ll i = 0; i < N; i++){
    ll c;
    cin >> c;
    ans = GCD(ans, c);
  }
  
  cout << ans << endl;
    
  
}

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

int main()
{
  int64_t N, a, ans = 0;
  cin >> N;
  map<pair<int, int>, bool> mp;
  for (int i = 1; i <= N; i++)
  {
    cin >> a;
    mp[make_pair(i, a)] = 1;
    if (mp.count(make_pair(a, i)))
      ans++;
  }
  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	vll a(n), b(n);
	rep(i, n){
		cin>>a[i];
		b[i] = a[i];
	}
	sort(all(b));
	ll m1 = b[b.size()-1];
	ll m2 = b[b.size()-2];

	rep(i, n){
		if (a[i] == m1){
			cout << m2 << "\n";
		}else{
			cout << m1 << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 4736
import sys


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


def solve():
    a, b, c, k = list(map(int, input().split()))

    if 1 <= k <= a + b:
        return min(a, k)
    
    if k > a + b:
        diff = k - a - b
        return a - diff

print(solve())


Measured memory_bytes: 9188
#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	long long fact = 1, sum[100001], ans = 0;
	for (i = 1; i <= N; i++) fact = fact * i % Mod;
	for (i = 2, sum[1] = 0; i <= N; i++) sum[i] = (sum[i-1] + div_mod(fact, i, Mod)) % Mod;
	for (i = 1; i <= N; i++) ans = (ans + (sum[i] + sum[N-i+1] + fact) * A[i]) % Mod;
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2900
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (100005)

using namespace std;

int dis[N],vis[N],n;
queue<int> Q;

il int calc(RG int x){
  RG int res=0; while (x) res+=x%10,x/=10; return res;
}

il void spfa(){
  for (RG int i=1;i<n;++i) dis[i]=calc(i),vis[i]=1,Q.push(i);
  dis[0]=calc(n),vis[0]=1,Q.push(0);
  while (!Q.empty()){
    RG int x=Q.front(),v; Q.pop();
    if (dis[v=x*10%n]>dis[x]){
      dis[v]=dis[x];
      if (!vis[v]) vis[v]=1,Q.push(v);
    }
    if (dis[v=(x+1)%n]>dis[x]+1){
      dis[v]=dis[x]+1;
      if (!vis[v]) vis[v]=1,Q.push(v);
    }
    vis[x]=0;
  }
  return;
}

int main(){
  cin>>n,spfa();
  cout<<dis[0];
  return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		Scanner scanner = new Scanner(System.in);
		int n = 12;
		int l = 12;
		while (scanner.hasNext()) {

			boolean[][] map = new boolean[l][n];
			for (int i = 0; i < l; i++) {
				String strs = scanner.next();
				for (int j = 0; j < n; j++) {
					if (strs.charAt(j) == '1') {
						map[i][j] = true;
					}
				}
			}
			int count = 0;
			for (int i = 0; i < l; i++) {
				for (int j = 0; j < n; j++) {
					if (map[i][j]) {
						count++;
						dfs(i, j, map, n, l);
					}
				}
			}
			System.out.println(count);
			if (scanner.nextLine().isEmpty()) {
				continue;
			}
		}
	}

	private static void dfs(int y, int x, boolean[][] map, int n, int l) {
		if (!map[y][x]) {
			return;
		}
		map[y][x] = false;
		int[] dx = { -1, 0, 0, 1 };
		int[] dy = { 0, 1, -1, 0 };
		for (int i = 0; i < 4; i++) {
			int py = y + dy[i];
			int px = x + dx[i];
			if (0 <= px && px < n && 0 <= py && py < l && map[py][px]) {
				dfs(py, px, map, n, l);
			}
		}
	}
}

Measured memory_bytes: 17236
#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)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

map<ll,int> prime_factor(ll n){
  map<ll, int> ret;
  for(ll i = 2; i*i <= n; i++){
    while(n % i == 0){
      ret[i]++;
      n/=i;
    }
  }
  if(n!=1)ret[n]=1;
  return ret;
}

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

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

  cout << prime_factor(gcd(a,b)).size()+1 << endl;

}



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

int main()
{
    int n,d=0;
    cin>>n;
    int a[n]; bool v[n]={0};
    for(int i=0; i<n; i++)
        cin>>a[i];
    a[0]--; v[0]=1;
    for(int i=1; i<n; i++)
    {
        if(a[i]<a[i-1])
        {
            if(!v[i-1]) a[i-1]--;
            else d=1;

            if(a[i]<a[i-1]) d=1;
        }
        else
        {
            if(a[i]>a[i-1])
            {
                a[i]--;
                v[i]=1;
            }
            if(a[i]==a[i-1])
                v[i]=1;
        }
    }
    if(d) cout<<"No\n";
    else cout<<"Yes\n";
  	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t w, a, b;
  cin >> w >> a >> b;
  
  int64_t ans = 0;
  
  if(a > b){
    if(a+w-b > 2*w){
      ans = a - (b+w);
    }
    else{
      ans = 0;
    }
  }
  
  else if(a < b){
    if(b+w-a > 2*w){
      ans = b - (a+w);
    }
    else{
      ans = 0;
    }
  }
  
  cout << ans << endl;

}
            

Measured memory_bytes: 3640