akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let t = vec![(1, 2), (2, 3)];

    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        let c = sc.read::<i64>();
        graph[a].push((b, -c));
    }

    let (dist, negative) = shortest_path(&graph, 0, std::i64::MAX);
    if negative[n - 1] {
        println!("inf");
    } else {
        println!("{}", -dist[n - 1]);
    }
}

pub fn shortest_path(graph: &Vec<Vec<(usize, i64)>>, start: usize, inf: i64) -> (Vec<i64>, Vec<bool>) {
    let n = graph.len();
    let mut dist = vec![inf; n];
    dist[start] = 0;
    for _ in 0..n {
        for v in 0..n {
            for &(to, cost) in &graph[v] {
                if dist[v] == inf || dist[to] <= dist[v] + cost {
                    continue;
                }
                dist[to] = dist[v] + cost;
            }
        }
    }

    let mut negative = vec![false; n];
    for _ in 0..n {
        for v in 0..n {
            for &(to, cost) in &graph[v] {
                if dist[v] == inf {
                    continue;
                }
                if dist[to] > dist[v] + cost {
                    dist[to] = dist[v] + cost;
                    negative[to] = true;
                }
                if negative[v] {
                    negative[to] = true;
                }
            }
        }
    }

    return (dist, negative);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include<stdio.h>
#define p(a) putchar(a);break
char S[3];

int main()
{
	for(;~scanf("%2s",S);)
	{
		if(S[0]==10)break;
		if(S[0]=='0'&&S[1]=='U')printf("nn");
		else
		{
			switch(S[0]-'0')
			{
			case 1:break;
			case 2:p('k');
			case 3:p('s');
			case 4:p('t');
			case 5:p('n');
			case 6:p('h');
			case 7:p('m');
			case 8:p('y');
			case 9:p('r');
			default:p('w');
			}
			switch(S[1])
			{
			case 'T':p('a');
			case 'L':p('i');
			case 'U':p('u');
			case 'R':p('e');
			default:p('o');
			}
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 540
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let mut a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };
    a.sort_by(|a, b| b.cmp(a));

    let mut queue = std::collections::VecDeque::new();
    queue.push_back(a[0]);
    let mut ans = 0;
    for i in 1..n {
        let x = queue.pop_front().unwrap();
        ans += x;
        queue.push_back(a[i]);
        queue.push_back(a[i]);
    }
    println!("{}", ans);
}

Measured memory_bytes: 7180
// nb_9960
  #include <bits/stdc++.h> 
  using namespace std; 
  #define fi(i,a,n) for (ll i=a; i < n; i++) 
  #define ll long long
  #define pb push_back 
  #define mp make_pair 
  #define F first 
  #define S second 
  #define all(x) x.begin(), x.end() 
  #define clr(x) memset(x, 0, sizeof(x)) 
  #define sortall(x) sort(all(x)) 
  typedef pair<ll, ll> pl; 
  typedef vector<ll> vl; 
  typedef vector<pl> vpii; 
  #define sz(a) int((a).size())
  #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 cpresent(c,x) (find(all(c),x) != c.end())
  #define MOD 1000000007
  #define PI 3.1415926536

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

    ll t = 1; 
    // cin >> t;

    while (t--) { 
      string s;
      cin>>s;
      if(s[s.size()-1]=='s'){
        s.push_back('e');
        s.push_back('s');
      }else{
        s.push_back('s');
      }
      cout<<s<<endl;
    }
    return 0; 
  } 


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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#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 repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int p = 1e9 + 7;
const int mod = p;
const int inf = 1e18;
const int maxn = 2e5+5;

void solve(){
	int n; cin>>n;
	int a[n];
	rep(i, 0, n) cin>>a[i];
	int mx = a[0];
	int ans = 0;
	rep(i, 1, n){
		mx = max(a[i], mx);
		ans += mx - a[i];
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); //io();
    //cout<<setprecision(12);
    int tc=1; //0cin>>tc; //int t = 1; 
    while(tc--){
    	//cout<<"Case #"<<t<<": "; ++t;
        solve();cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 5204
#include <stdio.h>

int main(void)
{
	int y, m, d;
	unsigned long long serial;
	while (~scanf("%d %d %d", &y, &m, &d)){
		serial = y * 10000 + m * 100 + d;

		if (serial < 18680908) puts("pre-meiji");
		else if (serial < 19120730) printf("meiji %d %d %d\n", y - 1867, m, d);
		else if (serial < 19261225) printf("taisho %d %d %d\n", y - 1911, m, d);
		else if (serial < 19890108) printf("showa %d %d %d\n", y - 1925, m, d);
		else printf("heisei %d %d %d\n", y - 1988, m, d);
	}
	return (0);
}

Measured memory_bytes: 608
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
int G[510][510];
int g[510][510];
vector<int> ans(MAX_N);

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=1;i<=m;i++){
        int l,r;
        cin>>l>>r;
        G[l][r]++;
    }
    // G[l][1]+G[l][2]+...+G[l][6]
    for(int i=1;i<510;i++){
        for(int j=1;j<510;j++){
            g[i][j]=G[i][j]+g[i][j-1];
        }
    }
    for(int i=0;i<q;i++){
        int s,t;
        cin>>s>>t;
        for(int j=s;j<=t;j++){
            ans[i]+=g[j][t];
        }
    }
    for(int i=0;i<q;i++) cout<<ans[i]<<endl;

}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 100000000000000001
#define PI 3.14159265
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

// string to integer stoi() Remember: it takes string not character
// string to long long stol()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll a,b,n;
    cin>>a>>b>>n;

    ll t = b-1;
    if(n>=t){
        ll t1 = (a*t)/b;
        cout<<t1;
    }
    else{
        ll t1 = (a*n)/b;
        cout<<t1;        
    }

    return 0;
} 

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

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

    for(int i = 0; i <= N; i++){
        int total = 0;
        for(int j = 0; j <= N; j++){
            if(i + j > N) break;
            total = 10000 * i + 5000 * j + 1000 * (N - i - j);
            if(total == Y){
                cout << i << ' ' << j << ' ' << (N - i - j) << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

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

int n, k;
string s;

char to_lower(char c){
  if (c == 'A'){
    return 'a';
  }else if (c == 'B'){
    return 'b';
  }else if (c == 'C'){
    return 'c';
  }
}

int main() {
  cin >> n >> k;
  cin >> s;
  s[k - 1] = tolower(s[k - 1]);
  cout << s << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string a;
	
	cin >> a;
	
	int size = a.size();
	
	bool flag1 = false;
	bool flag2 = false;
	
	if (size % 2 == 1) flag1 = true;
	if (a[0] != a[size - 1]) flag2 = true;
	
	if (flag1 && flag2) {
		cout << "First" << endl;
	} else if (flag1 || flag2) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
	
	
	return 0;
	
}

Measured memory_bytes: 640
def solve():
    N, M = map(int, input().split())
    s, c = [0] * M, [0] * M
    for i in range(M):
        s[i], c[i] = map(int, input().split())
    
    ans = 0
    while ans < 1000:
        str_ans = str(ans)
        len_str_ans = len(str(ans))
        if len_str_ans == N:
            cnt = 0
            for i in range(M):
                if len_str_ans < s[i]:
                    break
                if int(str_ans[(len_str_ans - 1) - (len_str_ans - s[i])]) == c[i]:
                    cnt += 1
            if cnt == M:
                print(ans)
                exit()
        ans += 1
    print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		String s = sc.next();
		if(a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  if(N%27==13||N%27==26){
    cout<<":("<<endl;
  }else {
	int a=N/1.08;
    
  
  if(N==a*1.08)cout<<a<<endl;
  else cout<<a+1<<endl;
  } 
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;

#define Max_effort ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define debug(x) cerr<<#x<<" = "<<(x)<< nl
#define nl "\n"
#define sp " "

int n;
string s;

int main() {
	Max_effort
	cin >> n >> s;
	ll ans = 0;
	for(int i=0; i< n-2; i++){
		if(s[i]== 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
			ans++;
		}
	}
	cout << ans;
}



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

using namespace std;

typedef long long LL;

#define MAXN 200010

int n;
int h[200010], a[200010];
LL tree[MAXN];

void update(int pos, LL val) {
    while (pos<MAXN) {
        tree[pos]=max(tree[pos], val);
        pos+=(pos&-pos);
    }
}

LL get(int pos) {
    LL ret=0;
    while (pos>0) {
        ret=max(ret, tree[pos]);
        pos-=(pos&-pos);
    }
    return ret;
}

int main() {
    cin>>n;
    for (int i=0;i<n;i++) scanf("%d", &h[i]);
    for (int i=0;i<n;i++) scanf("%d", &a[i]);
    memset(tree, -1, sizeof(tree));
    update(h[0], a[0]);
    LL ret=a[0];
    for (int i=1;i<n;i++) {
        LL val=a[i];
        if (h[i]>1) val+=get(h[i]-1);
        update(h[i], val);
        ret=max(ret, val);
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<vector<int> > cnt(10, vector<int>(10));
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    int l = s.size();
    cnt[s[0] - '0'][s[l - 1] - '0']++;
  }
  int ans = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x,y) fixed<<setprecision(y)<<x
#define pq priority_queue<int>
#define mpq priority_queue<int,vector<int>,greater<int>>
#define gcd(x,y) __gcd(x,y)
#define mp make_pair

double dp[3000][3000];

double cointoss(double a[],int n,int i,int j)
{
	if(i+j>n) return 0;
	if(i+j==n && i>j)  return 1;
	else if(i+j==n && j>i) return 0;
	else if(dp[i][j]!=-1) return dp[i][j];
	else
	{
		dp[i][j]=a[i+j]*cointoss(a,n,i+1,j)+(1-a[i+j])*cointoss(a,n,i,j+1);
		return dp[i][j];
	}

}



int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j;
    cin>>n;
    double a[n];
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<=n;i++)
    {
    	for(j=0;j<=n;j++) dp[i][j]=-1;
    }
    cout<<pre(cointoss(a,n,0,0),9)<<endl;
	return 0;
}


Measured memory_bytes: 74324
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String Red=sc.next();
    String Blue=sc.next();
    int N=sc.nextInt();
    int M=sc.nextInt();
    String Ball=sc.next();
    
    if(Ball.equals(Red)) System.out.print((N-1)+" "+M);
    if(Ball.equals(Blue)) System.out.print(N+" "+(M-1));
  }
}


Measured memory_bytes: 21844
'''
c-yan
書き換え後の値を大きい方から順に並べて、
その数を書き換え数分追加して、追加数が n を超えたら、
ソートして、大きい方から n 個とればいい
'''

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)#第二引数でソート
t = 0
for B, C in BC:
    A.extend([C] * B)#extendで追加
    t += B
    if t > N:
        break
A.sort(reverse=True)
print(sum(A[:N]))

Measured memory_bytes: 34880
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    x, y, z = map(int, input().split())
    print(int(x*y*0.5))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
s = input()
q = int(input())

rev = False

forward = ''
back = ''

for i in range(q):
    tfc = input()
    if len(tfc) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        t, f, c = tfc.split()
        if f == '1':
            if rev:
                back += c
            else:
                forward += c
        else:
            if rev:
                forward += c
            else:
                back += c

s = forward[::-1] + s + back
if rev:
    s = s[::-1]

print(s)


Measured memory_bytes: 4284
#include <cstdio>
#include <vector>
using namespace std;

int N;
int a, b;
vector<vector<int> > G(100010);
vector<vector<int> > G2(100010);
int fa[100010];
int vis[100010];
int p[100010];
int pL;
int wc;

void dfs(int u)
{
	int i;
	int v;
	for(i=0; i<G[u].size(); i++){
		v = G[u][i];
		if(vis[v] == 0){
			vis[v] = 1;
			G2[u].push_back(v);
			fa[v] = u;
			dfs(v);
		}
	}
}

void dfs2(int u)
{
	int i;
	int v;
	for(i=0; i<G2[u].size(); i++){
		v = G2[u][i];
		vis[v] = 1;
		wc ++;
		dfs2(v);
	}
}

void solve()
{
	vis[0] = 1;
	dfs(0);
	int u = N-1;
	pL = 0;
	while(u != 0){
		p[pL] = u;
		pL ++;
		u = fa[u];
	}
	p[pL] = 0;
	pL ++;
	int i, j;
	i = 0;
	j = pL-1;
	while(i+1<j-1){
		i ++;
		j --;
	}
	wc = 1;
	dfs2(p[i]);
	if(wc < N-wc)
		printf("Fennec\n");
	else
		printf("Snuke\n");
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d", &N);
	for(i=0; i<N-1; i++){
		scanf("%d %d", &a, &b);
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	solve();
	return 0;
}

Measured memory_bytes: 17024
n = int(input())

words = []
dict = {}
for i in range(n):
    s = input()
    words.append(s)
    if s not in dict:
        dict[s] = 0
    dict[s] += 1

max = max(dict.values())
for s in sorted([d for d in dict if dict[d] == max]):
    print(s)

Measured memory_bytes: 34564
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  map<string,Int> cnt;

  Int N;
  cin>>N;
  for(Int i=0;i<N;i++){
    string s;
    cin>>s;
    cnt[s]++;
  }

  cout<<"AC x "<<cnt["AC"]<<endl;
  cout<<"WA x "<<cnt["WA"]<<endl;
  cout<<"TLE x "<<cnt["TLE"]<<endl;
  cout<<"RE x "<<cnt["RE"]<<endl;




  return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n, k; cin >> n >> k;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	bool odd, even;
	odd = even = true;
	REP(i, n) {
		if (a[i] % 2) even = false;
		else odd = false;
	}
	bool allSame = true;
	bool diffFlag = true;
	int diff = INT_MAX;
	REP(i, n - 1) {
		if (abs(a[i] - a[i+1]))
			diff = min(diff, abs(a[i] - a[i+1]));
	}
	REP(i, n - 1) {
		if (a[i] != a[i+1])
			allSame = false;
		if (abs(a[i] - a[i+1]) % diff)
			diffFlag = false;
	}

	if (k > *max_element(a.begin(), a.end())) {
		cout << "IMPOSSIBLE" << '\n';
	}
	else if (find(a.begin(), a.end(), k) != a.end()) {
		cout << "POSSIBLE" << '\n';
	}
	else if (allSame) {
		cout << ((k == a[0]) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
	}
	else if (diffFlag) {
		cout << ((k % diff == 0) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
	}
	else {
		if (k % 2) {
			bool ok = true;
			if (even) ok = false;
			if (k == 1 && (even || odd)) ok = false;
			cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
		}
		else {
			cout << "POSSIBLE" << '\n';
		}
	}
    return 0;
}


Measured memory_bytes: 3736
s = input()
s2 = s.replace("A","")
s4 = set(s) - set(list("KIHBRA"))

if s2 == "KIHBR" and s4 == set() and s.index("H")-s.index("K") == 2 and s.count("AA") == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
    if A[i]>=B[i]:
        ans += B[i]
    else:
        ans += A[i]
        if B[i]-A[i]>=A[i+1]:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += B[i]-A[i]
            A[i+1] -= B[i]-A[i]
print(ans)


Measured memory_bytes: 81892
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,a[100000],b[100000];
    long long c=0,d=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    
    if(n%2==0){
        b[0]=a[n/2];
        for(int i=1;i<n;i++){
            if(i%2==0){
                b[i]=a[n/2+i/2];
            }else{
                b[i]=a[i/2];
            }
            c+=abs(b[i]-b[i-1]);
        }
    }else{
        b[0]=a[n/2];
        for(int i=1;i<n;i++){
            if(i%2==0){
                b[i]=a[(i-1)/2];
            }else{
                b[i]=a[(n+i)/2];
            }
            c+=abs(b[i]-b[i-1]);
        }
        b[0]=a[n/2];
        for(int i=1;i<n;i++){
            if(i%2==0){
                b[i]=a[n-i/2];
            }else{
                b[i]=a[i/2];
            }
            d+=abs(b[i]-b[i-1]);
        }
    }
    cout<<max(c,d)<<endl;
}


Measured memory_bytes: 1024
MOD = 998244353
n, m, k = map(int, input().split())

fact = [0]*(n+1)
fact[0] = 1
for i in range(1, n+1):
    fact[i] = fact[i-1]*i % MOD

invfact = [0]*(n+1)
invfact[n] = pow(fact[n], MOD-2, MOD)
for i in reversed(range(n)):
    invfact[i] = invfact[i+1]*(i+1) % MOD


def nCk(n, k):
    return fact[n]*invfact[k]*invfact[n-k]


ans = 0
for i in range(k+1):
    ans += m*pow(m-1, n-1-i, MOD)*nCk(n-1, i)
    ans %= MOD
print(ans)

Measured memory_bytes: 24572
a,b,c = (int(x) for x in input().split())
if a+b <= a+c <= b+c or a+b <= b+c <= a+c:
  print (a+b)
elif a+c <= a+b <= b+c or a+c <= b+c <= a+b:
  print (a+c)
else:
  print (b+c)


Measured memory_bytes: 9008
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(long[]);

    foreach (a; as) if (a >= N) goto solve;
    writeln(0);
    return;
    solve:

    long l, r = (10L^^16+1000)*N+1;
    while (l+1 < r) {
        auto m = (l+r)/2;
        auto aa = as.dup;
        auto K = m;
        auto ds = new long[](N);
        long d;
        for (;;) {
            ds[] = 0;
            d = 0;
            foreach (i, ref a; aa) {
                if (i) ds[i] += ds[i-1];
                a += d;
                if (a >= N) {
                    auto x = a / N;
                    if (K < x) goto ng;
                    K -= x;
                    a %= N;
                    ds[i] += x;
                    d += x;
                }
            }
            bool ok = true;
            foreach (i, ref a; aa) {
                a += d - ds[i];
                if (a >= N) ok = false;
            }
            if (ok) break;
        }
        r = m;
        continue;
        ng:
        l = m;
    }
    writeln(r);
}

Measured memory_bytes: 2792
N = int(input())
A = list(map(int,input().split()))
ans = 0
cnt = 0
mini = float("inf")
for i in range(N):
    ans += abs(A[i])
    mini = min(mini, abs(A[i]))
    if A[i] < 0:
        cnt += 1
        
if cnt % 2:
    ans -= 2 * mini
print(ans)

Measured memory_bytes: 64752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int h,w;

int main(){
	cin >> h >> w;
	vector<P> p;
	rep(i,h){
		ll num;
		cin >> num;
		p.push_back(P(num,0));
	}
	rep(i,w){
		ll num;
		cin >> num;
		p.push_back(P(num,1));
	}
	sort(ALL(p));
	ll cnt[2] = {};
	ll def = 0;
	ll prev = p[0].second;
	ll ans = 0;
	rep(i,p.size()){
		ll num = p[i].first;
		bool now = p[i].second;
		if(prev != now)def = cnt[prev];
		cnt[now]++;
		prev = now;
		if(now == 0)num *= (w+1-def);
		else num *= (h+1-def);
		// cout << "!"<< num << endl;
		ans += num;
		prev = now;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍


int main(){
	ll n;cin>>n;
    cout<<((n-1)/111+1)*111<<endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

import System.IO

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [n, m] <- readIntList
  putStrLn $ if n <= m then "unsafe" else "safe"


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#include<string>
using namespace std;
int dp[100009];
string str;
int main()
{
    cin>>str;
    int i;
    int len=str.length();
    dp[0]=1;
    for(i=0;i<len;i++)
    {
        if(i>=4)
        {
            if(str.substr(i-4,5)=="dream"||str.substr(i-4,5)=="erase")
            {
                if(i==4)dp[i]=1;
                else
                dp[i]=max(dp[i],dp[i-5]);
            }
        }
        if(i>=5)
        {
            if(str.substr(i-5,6)=="eraser")
            {
                if(i==5)dp[i]=1;
                else
                dp[i]=(dp[i],dp[i-6]);
            }
        }
        if(i>=6)
        {
            if(str.substr(i-6,7)=="dreamer")
            {
                if(i==6)dp[i]=1;
                else
                dp[i]=(dp[i],dp[i-7]);
            }
        }
    }
    if(dp[len-1])printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 896
N,Q = map(int,input().split())
S = input()
QList = []
for _ in range(Q):
    l,r = map(int,input().split())
    QList.append([l,r])

Data = [0]*(N)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        Data[i+1] = 1

Acc = [0]*(N+1)
for i in range(N):
    Acc[i+1] = Acc[i]+Data[i]

#print(Acc)
for q in QList:
    l = q[0]
    r = q[1]
    ans = Acc[r]-Acc[l-1]
    if l >= 2:
        if S[l-1] == 'C' and S[l-2] == 'A':
            ans -= 1
    print(ans)


Measured memory_bytes: 25224
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

func bitCount(n uint) int {

        x := uint64(n)

        const m = 1<<64 - 1
        const m0 = 0x5555555555555555
        const m1 = 0x3333333333333333
        const m2 = 0x0f0f0f0f0f0f0f0f

        x = x>>1&(m0&m) + x&(m0&m)
        x = x>>2&(m1&m) + x&(m1&m)
        x = (x>>4 + x) & (m2 & m)
        x += x >> 8
        x += x >> 16
        x += x >> 32

        return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
        return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////
func cmpStrNum(a, b string) bool {
        if a == "---" {
                return true
        }
        if len(a) < len(b) {
                return true
        } else if len(a) > len(b) {
                return false
        }
        return a < b
}

func main() {
        line := nextLine()

        spl := intSprit(line)

        N := spl[0]

        a := intSprit(nextLine())
        tb := []int{2, 5, 5, 4, 5, 6, 3, 7, 6}

        dp := make([]string, 100000)
        for i := 1; i < len(dp); i++ {
                dp[i] = "---"
        }
        dp[0] = ""

        for i := 0; i <= N; i++ {
                if dp[i] == "---" {
                        continue
                }
                for _, v := range a {
                        if cmpStrNum(dp[i+tb[v-1]], dp[i]+strconv.Itoa(v)) {
                                dp[i+tb[v-1]] = dp[i] + fmt.Sprint(v)
                        }
                }
        }
        fmt.Println(dp[N])
}

Measured memory_bytes: 131008
def resolve():
    import sys
    from operator import itemgetter
    readline = sys.stdin.readline
    N = int(readline())
    LR = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        LR[i] = [p-l, p+l]
    LR.sort(key=itemgetter(1))

    pre_r = -(10**18)
    count = 0
    for l, r in LR:
        if pre_r <= l:
            count += 1
            pre_r = r
    print(count)

resolve()

Measured memory_bytes: 21348
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct pole
{
    int x, y;
};

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int odp = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            for (int k = 0; k < n; ++k)
            {
                for (int l = 0; l < m; ++l)
                {
                    if (a[i][j] == '.' && a[k][l] == '.')
                    {
                        queue<pole> Q;
                        vector< vector<int> > odl(n, vector<int>(m, -1));
                        Q.push({i, j});
                        odl[i][j] = 0;
                        while (!Q.empty())
                        {
                            pole akt = Q.front();
                            Q.pop();
                            if (akt.x == k && akt.y == l)
                                break;
                            for (int q = 0; q < 4; ++q)
                            {
                                pole nowy = {akt.x + dx[q], akt.y + dy[q]};
                                if (nowy.x >= 0 && nowy.x < n && nowy.y >= 0 && nowy.y < m && odl[nowy.x][nowy.y] == -1 && a[nowy.x][nowy.y] == '.')
                                {
                                    Q.push(nowy);
                                    odl[nowy.x][nowy.y] = odl[akt.x][akt.y] + 1;
                                }
                            }
                        }
                        odp = max(odp, odl[k][l]);
                    }
                }
            }
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main(){
	double x;
    ll count=0,y;
  	scanf("%lf %lld", &x,&y);
    double a,b;
    for(ll i=0;i<x;i++){
    	scanf("%lf %lf",&a,&b);
        if(sqrt(pow(a,2)+pow(b,2))<=y){
            	count++;
                //cout<<"--"<<a<<b<<"--";
        }
    }
    printf("%lld",count);
}

Measured memory_bytes: 3232
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int R, N;
    int[] L = new int[41];
    const P = 20;
    bool input() {
        scanf("%d %d\n", &R, &N);
        if (R == 0 && N == 0) return false;
        L[] = 0;
        foreach (i; 0 .. N) {
            int l, r, h;
            scanf("%d %d %d\n", &l, &r, &h);
            foreach (j; l .. r) {
                L[j + P] = max(L[j + P], h);
            }
        }
        return true;
    }
    bool C(double t) {
        if (min(L[P - 1], L[P]) < t) return false;
        for (int x = -19; x <= 20; x++) {
            int y = min(L[x + P], L[x + P - 1]);
            //writeln([t]);
            //writeln([x, y]);
            if (x * x + (t - R - y) * (t - R - y) < R * R) return false;
        }
        return true;
    }
    void solve() {
        double lb = 0, ub = 21;
        foreach (_; 0 .. 100) {
            double mid = (lb + ub) / 2;
            if (C(mid)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        writefln("%.4f", lb);
    }
    while (input) solve;
}

Measured memory_bytes: 1148
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll n,x;
ll nums[2009];

ll calc(int wid){
    map<int,int> dic;
    int idx=0;
    for(;idx<wid;idx++) dic[nums[idx]]++;
    ll res=0;
    rep(i,n){
        dic[nums[idx]]++;
        res+=dic.begin()->first;
        dic[nums[i]]--;
        if(dic[nums[i]]<=0){
            dic.erase(nums[i]);
        }
        idx=(idx+1)%n;
    }
    res+=wid*x;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>x;
    rep(i,n) cin>>nums[i];
    
    ll res=0;
    rep(i,n) res+=nums[i];
    
    rep1(i,n-1){
        if(i*x>res) break;
        res=min(res,calc(i));
    }
    cout1(res);
}

Measured memory_bytes: 384
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
    	Scanner itr = new Scanner(System.in);
      	long a = (long)itr.nextInt();
      	long b = (long)itr.nextInt();
      	long c = (long)itr.nextInt();
      
      	long item1 = 4L * a * b;
      	long item2 = (c - a - b) * (c - a - b);
      	
      	if ((c - a - b) <= 0) {
          System.out.println("No");
          return;
        }
      	
      	if (item1 < item2)
          System.out.println("Yes");
      	else
          System.out.println("No");
    } 
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int N, Q;
bool dp[101010];
bool dp2[101010];
//-----------------------------------------------------------------
int main() {
	cin >> N >> Q;

	dp[1] = true;
	dp2[2] = true;

	int bb = 1;
	rep(i, 0, Q) {
		int a, b;
		scanf("%d %d", &a, &b);

		swap(dp[a], dp[b]);
		swap(dp2[a], dp2[b]);
		if (dp[a]) bb = a;
		if (dp[b]) bb = b;
		dp2[bb - 1] = dp2[bb - 1] | dp[bb];
		dp2[bb + 1] = dp2[bb + 1] | dp[bb];
	}

	int ans = 0;
	rep(i, 1, N + 1) if (dp[i] || dp2[i]) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


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

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var N, M int

func main() {
	sc.Split(bufio.ScanWords)

	N, M = nextInt(), nextInt()
	a := make([][]int, 3)

	for i := 0; i < N; i++ {
		for j := 0; j < 3; j++ {
			a[j] = append(a[j], nextInt())
		}
	}

	res := 0
	for bit := uint(0); bit < (1 << 3); bit++ {
		var b []int
		for i := 0; i < N; i++ {
			tmp := 0
			for j := uint(0); j < 3; j++ {
				if bit&(1<<j) == 1<<j {
					tmp += a[j][i]
				} else {
					tmp -= a[j][i]
				}
			}
			b = append(b, tmp)
		}

		sort.Sort(sort.Reverse(sort.IntSlice(b)))
		sum := 0
		for i := 0; i < M; i++ {
			sum += b[i]
		}
		res = max(res, sum)
	}

	fmt.Println(res)

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


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

bool match(char c1, char c2){
    return ((c1 == c2) || (c1 == '?') || (c2 == '?'));
}

int main(){
    string A, B, C; cin >> A >> B >> C;
    int LA = A.length(), LB = B.length(), LC = C.length();

    vector<bool> AB(100000,true), AC(100000,true), BC(100000,true);

    rep(i, LA) rep(j, LB) if(!match(A[i], B[j])) AB[i-j+50000] = false;
    rep(i, LA) rep(j, LC) if(!match(A[i], C[j])) AC[i-j+50000] = false;
    rep(i, LB) rep(j, LC) if(!match(B[i], C[j])) BC[i-j+50000] = false;

    int ans = 1e8;
    for(int i = -4000; i<=4000; i++){
        for(int j = -4000; j<=4000; j++){
            if(AB[i+50000] && AC[j+50000] && BC[j-i+50000]){
                int L = min(0, min(i,j));
                int R = max(LA,max(i+LB, j+LC));
                ans = min(ans, R-L);            
            }
        }
    }

    cout << ans << endl;
    
    

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int sum;
  while(cin >> str && str!="0"){
    sum = 0;
    for(int i=0,l=str.size();i<l;i++) sum += str[i]-'0';
    cout << sum << endl;
  }
}


Measured memory_bytes: 3152
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const int mod=1000000007;

ll pow(ll n,ll k){
  if(k<0)k+=mod-1;
  ll ret=1;
  while(k>0){
    if(k&1)ret=ret*n %mod;
    n=n*n %mod;
    k>>=1;
    }
  return ret;
  }

int main(){
  ll n;cin>>n;
  string s;cin>>s;
  ll m=s.size();
  ll dp[5010][5010];
  dp[0][0]=1;
  rep(i,n+1){
    rep(j,n-1)dp[i+1][j+1]=(2*dp[i][j]+dp[i][j+2])%mod;
    dp[i+1][0]=(dp[i][1]+dp[i][0])%mod;
    dp[i+1][n]=2*dp[i][n-1]%mod;
    }
  ll ans=dp[n][m]*pow(2,-m) %mod;
  cout<<ans<<endl;
  return 0;
  }

Measured memory_bytes: 196224
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

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

    int ans = INT_MAX;
    for( char c='a'; c<='z'; c++ ) {
        int maximum = INT_MIN;
        int count = 0;
        for( char s : S ) {
            if( s == c ) { count = 0; }
            else { count ++; }
            maximum = max( maximum, count );
        }
        ans = min( ans, maximum );
    }

    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
/////////////////////////////////
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> ma(n);
    rep(i, n)
    {
        cin >> a[i];
        ma[i] = a[i];
    }
    sort(ma.begin(), ma.end());
    int M = ma[n - 1];
    rep(i, n)
    {
        if (a[i] != M)
            cout << M << endl;
        else
            cout << ma[n - 2] << endl;
    }
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << " "
#define debugln(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define vvdebug(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N; cin >> N;
	if (N == 0) {
		cout << 0 << endl;
	} else {
		string ans = "";
		for (int k = 0; N != 0; k++) {
			// debugln(N);
			if (k % 2 == 0) {
				if (N % 2) {
					ans = '1' + ans;
					N -= 1;
					N /= 2;
				} else if (N % 2 == 0) {
					ans = '0' + ans;
					N /= 2;
				}
			} else if (k % 2 != 0) {
				if (N % 2) {
					ans = '1' + ans;
					N += 1;
					N /= 2;
				} else if (N % 2 == 0) {
					ans = '0' + ans;
					N /= 2;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n;
  cin>>n;
  ll prime[101]={};
  for(int i=1;i<=n;i++){
    ll tmp=i;
    for(int j=2;j<=100;j++){
      if(tmp%j==0){
        prime[j]++;
        tmp/=j;
        j--;
      }
      if(tmp<=1) break;
    }
  }
  ll c[5]={};
  ll nana[5]={3,5,15,25,75};

  for(int i=2;i<=n;i++){
    for(int j=0;j<5;j++){
      if(nana[j]-1<=prime[i]) c[j]++;
    }
  }

  ll ans=0;
  /*ans+=max(0ll,c[0]*c[1]*(c[1]-1)/2);
  ans+=c[0]*c[3];
  ans+=c[1]*c[2];
  ans+=c[4];*/
  for(int i=2;i<=n;i++){
    if(prime[i]<2) continue;
    for(int j=2;j<=n;j++){
      if(i==j) continue;
      if(prime[j]<4) continue;
      for(int k=j+1;k<=n;k++){
        if(i==k) continue;
        if(prime[k]<4) continue;
        ans++;
      }
    }
  }

  for(int i=2;i<=n;i++){
    if(prime[i]<4) continue;
    for(int j=2;j<=n;j++){
      if(i==j) continue;
      if(prime[j]<14) continue;
      ans++;
    }
  }

  for(int i=2;i<=n;i++){
    if(prime[i]<2) continue;
    for(int j=2;j<=n;j++){
      if(i==j) continue;
      if(prime[j]<24) continue;
      ans++;
    }
  }

  ans+=c[4]; 

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
n,d = map(int,input().split())
d_list  = []
ans_list = []
for i in range(n):
     d_list.append(list(map(int,input().split())))

cnt = 0
for i in range(len(d_list)-1):
    for j in range(i+1,len(d_list)):
        tmp = 0
        for n in range(d):
            tmp += (d_list[i][n] - d_list[j][n])**2
        if int(np.sqrt(tmp))**2 == tmp:
            cnt += 1
            
print(cnt)

Measured memory_bytes: 12500