akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

 // void dfs(ll node){
 // 	vis[node]=1;
 // 	res.pb(node);
 //    vector<ll> ans;


 // 	for(auto i:v[node]){
 // 		if(!vis[i]){
 // 			ans.pb(i);

 // 		}
 // 	}
 // 	sort(ans.begin(),ans.end());

 // 	for(auto i:ans){
 // 		if(!vis[i])
 // 			dfs(i);
 // 	}




 // }
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
bool sortbyme(const pair<int,int> &a, 
              const pair<int,int> &b){
	return (a.first+a.second > b.first+b.second);

}
// ll dp[1000000];
// ll tot=INT_MAX;


// ll dmch(vector<ll> a,ll ind,ll x,ll n){



// 	if(ind>=n-1)return 0;
// 	else if(dp[ind]!=-1){
// 		return dp[ind];

// 	}
// 	else{
// 		ll ans=INT_MAX;
// 		for(ll i=1;i<=2;i++)
// 			if(i+ind<n)
// 			{
// 				ans=min(abs(a[ind]-a[ind+i])+dmch(a,ind+i,x,n),ans);

// 			}
// 			else
// 				break;

// 		// ans=min(a[ind]+dmch(a,ind+1LL,x,n),min(a[ind]+dmch(a,ind+2ll,x,n)+x,a[ind]+x*2+dmch(a,ind+3ll,x,n)));
// 		dp[ind]=ans;
// 		return dp[ind];

// 	}
// }
void solve(){
ll n;
cin>>n;
vector<ll> v(n);
for(ll i=0;i<n;i++)cin>>v[i];
sort(v.begin(),v.end());
ll ans=0;
for(ll i=1;i<=n-1;i++){
	ans+=v[n-1- i/2];
	//cout<<ans<<" ";


}
cout<<ans<<endl;



return;
}



int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    

    ll t;
    t=1;
   //cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 4736
//Vivek
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) int(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define inf LONG_MAX
const int mod = 1000000007;

using namespace std;

#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 2*1e5 + 10;

#define int ll
int n, m, x, y, q, k;
int a[N];
ll pre[N];
string s;

main(){_

	cin>>n>>k;
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
	}

	for (int i = 1; i <= n; ++i)
	{
		pre[i] = pre[i-1];
		pre[i] += abs(a[i] - a[i-1]);
		trace(i, pre[i], a[i]);
	}
// 330
	ll ans = 3e18;
	for (int i = 1; i+k-1 <= n; ++i)
	{
		if(a[i+k-1] >= 0 and a[i] >= 0){
			smin(ans, abs(a[i+k-1]));
		}
		else if(a[i+k-1] >= 0 and a[i] < 0){
			smin(ans, min(2*abs(a[i+k-1]) + abs(a[i]), 2*abs(a[i]) + abs(a[i+k-1])));
		}
		else if(a[i+k-1] < 0 and a[i] < 0){
			smin(ans, abs(a[i]));
		}
		trace(i, ans, a[i+k-1], a[i]);
/*		if(a[i+k-1] == 0){
			smin(ans, abs(a[i]));
		}
		else{
			smin(ans, pre[i+k-1] - pre[i] + 1LL*abs(a[i]));
		}
*/	}

	cout<<ans;

	return 0;
}
/*
5
3              
-100000 -800000 -60000 -4000 -2000
5 3
-400 -210 -140 60 150
330
*/

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

int main() {
  string s[3];
  string Temp;
  string T;
  string a;

  cin >> s[0] >> s[1] >> s[2];

  Temp = s[1];
  T = Temp[0];

  a = 'A' + T + 'C'; 

  cout << a << endl;

return 0;

}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph2 {
	private int totalVertex;
	// adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	// adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	// if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;

	public Graph2() {
		totalVertex = 0;
	}

	public int getTotalVertex() {
		return totalVertex;
	}

	// load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for (i = 0; i < totalVertex; i++) {
			for (j = 0; j < totalVertex; j++) {
				adjWeight[i][j] = in.nextInt();
				if (adjWeight[i][j] != -1) {
					adjMatrix[i][j] = 1;
				}
			}
			ifSettled[i] = false;
		}
		in.close();
	}

	// return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}

	// return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for (int v = 0; v < totalVertex; v++) {
			if (adjMatrix[u][v] == 1)
				tmp.add(v);
		}
		return tmp;
	}

	// return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for (int v = 0; v < totalVertex; v++) {
			if ((adjMatrix[u][v] == 1) && (ifSettled[v] == false))
				tmp.add(v);
		}
		return tmp;
	}

	// return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for (v = 0; v < totalVertex; v++) {
			if ((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}

	// implement the following
	public int[] Dijkstra(int x) {
		int[] map = new int[totalVertex];
		for (int i = 0; i < totalVertex; i++) {
			map[i] = Integer.MAX_VALUE;
		}

		map[x] = 0;
		ifSettled[x] = true;

		int set = x;
		boolean cow = true;
		LinkedList<Integer> neighbors;

		while (cow) {
			neighbors = getUnsettledNeighbors(set);
			for (int i : neighbors) {
				map[i] = Math.min(map[i], getWeight(set, i));
			}
			set = getUnsettledNearest(map);
			ifSettled[set] = true;
			cow = false;
			for (int i = 0; i < totalVertex; i++) {
				if (ifSettled[i] == false) {
					cow = true;
				}
			}
		}
		return map;
	}
}

public class Main{
	public static void main(String[] args) {
		Graph2 g = new Graph2();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		int p = 0;
		for (int i = 0; i < g.getTotalVertex(); i++) {
			p += dist[i];
		}
		System.out.println(p);
	}
}



Measured memory_bytes: 40768
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {

        static void Main(string[] args)
        {
          var N = int.Parse(Console.ReadLine());
          //var S = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var S = Console.ReadLine().ToCharArray();
          for(int i = 0; i < S.Length ;i++){
            //Console.WriteLine((int)S[i]);
            int tmp = S[i]+N;
            if(tmp > 90){
              tmp = (tmp-90)+64;
            }
            S[i] = (char) tmp;
            
          }
          Console.WriteLine(String.Join("",S));
        }
  

}







Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N, A, B; cin >> N >> A >> B;
    cout << min(A * N, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (U==S){
        A--;
    }else{
        B--;
    }
    cout << A << "  " << B;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
const int N = 1e5;
using namespace std;

int main(){
	int n;
	char ch[110];
	while(cin>>n){
		int p=0,w=0,g=0,y=0;
		for(int i=1; i<=n; ++i){
			cin>>ch[i];
			if(ch[i] == 'P')p=1;
			if(ch[i] == 'W')w=1;
			if(ch[i] == 'G')g=1;
			if(ch[i] == 'Y')y=1;
		}
		int sum = p + w + g + y;
		if(sum == 1)cout<<"One";
		if(sum == 2)cout<<"Two";
		if(sum == 3)cout<<"Three";
		if(sum == 4)cout<<"Four";
	}

	return 0;	
}

Measured memory_bytes: 256
from collections import deque
def bfs(bldg):
    dict = {}
    
    que = deque([(bldg[0][0],0,0),(bldg[1][0],1,0)])

    while len(que):
        h, b, t = que.popleft()
        try:
            if dict[(h, b)] <= t:
                continue
        except KeyError:
            dict[(h, b)] = t
        
        if h == len(bldg[0]) - 3:
            return t
        t += 1
        if 100 < t:
            break
        que.append((bldg[b^1][h + 2],b^1,t))
    return 'NA'

def building():
    bldg = f.readline().split() + ['2', '2']    
    
    scaffold = 0    
    for i in range(len(bldg)):
        if '2' == bldg[i]:
            bldg[i] = scaffold
        else:
            scaffold = i
        if '0' == bldg[i]:
            bldg[i] = i

    scaffold = None
    for i in reversed(range(len(bldg))):
        if '1' == bldg[i]:
            if scaffold is None:
                scaffold = i
            bldg[i] = scaffold
        else:
            scaffold = None
    return bldg

import sys
f = sys.stdin


while True:
    n = int(f.readline())
    if n == 0:
        break
    print(bfs([building(),building()]))

Measured memory_bytes: 6772
T=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
N=gets.to_i
A=[0,1]
(2..N).each{|i|A<<T.select{|e|e<=i}.map{|e|A[i-e]+1}.min}
p A[N]

Measured memory_bytes: 2940
// template version 1.2
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0LL)
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

template<typename A, size_t N, typename T> // n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n;cin>>n;
  int L[2*n];
  rep(i, 2*n){
    cin>>L[i];
  }
  sort(L, L+2*n);

  int res = 0;
  rep(i, 2*n){
    if (i%2==0){
      res += L[i];
    }
  }
  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
n,k=map(int,input().split())
print(((n+2-k)*(k*n-k*k+k)+(n+2-k)*(n+1-k)*(n+1-2*k)//2-(n-k+1)*(n-k+2)*(2*n-2*k+3)//6+(n+2-k))%1000000007)

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

int main() {
    int N;
    cin >> N;
    vector<int> D(N, 0);

    for (int i = 0; i < N; i++) cin >> D.at(i);
    sort(D.begin(), D.end());

    int n_duplicates = 0;
    for (int i = 1; i < N; i++) {
        if (D.at(i-1) == D.at(i)) n_duplicates += 1;
    }
    cout << N - n_duplicates << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
int main(){
    int N,M;
    cin >> N >> M;
    int L[M],R[M]={};
    int minR = 100000;
  	int maxL = 0;
    for (int i = 0; i<M;i++){
        cin >> L[i] >> R[i];
        maxL = max(maxL,L[i]);
        minR = min(minR,R[i]);
    }
    if(maxL<=minR){
    	cout << minR - maxL + 1<<endl;
    }else {
        cout << 0 <<endl;
    }

    
    
 
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n,b;
    ll bb;
    cin >> n;
    vector<ll>binary(n);
    cin >> b;
    bb = b;
    binary[0] = b;
    rep(i, n-1) {
        cin >> b;
        binary[i+1] = b;
        bb ^= b;
    }
    ll res = 0;
    rep(i, n - 1) {
        res = bb ^ binary[i];
        cout << res << " ";
    }
    res = bb ^ binary[n - 1];
    cout << res << endl;

    return 0;

}


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

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
	char a[4],b[4],c[4];
	scanf("%s %s %s",a,b,c);
	printf("%c%c%c",a[0],b[1],c[2]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
      cin>>a[i];
      sum+=a[i];
    }
    sum/=n;
    int d=sum-1,b=sum,c=sum+1;
    int ans=0;
    rep(i,n){
      ans+=(a[i]-d)*(a[i]-d);
    }
    int cnt=0;
    rep(i,n){
      cnt+=(a[i]-b)*(a[i]-b);
    }
    if(ans>cnt) ans=cnt;
    cnt=0;
    rep(i,n){
      cnt+=(a[i]-c)*(a[i]-c);
    }
    if(ans>cnt) ans=cnt;
    cout<<ans<<endl;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	long long int n,A[100007],B[100007],c=0;
	cin >> n;
	for (int i = 0; i < n+1; ++i)
	{
		cin >> A[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> B[i];
	}
	for (int i = 0; i < n; ++i)
	{
		long long int h = min(A[i],B[i]);
		A[i]-=h;B[i]-=h;c+=h;
		h = min(A[i+1],B[i]);
		A[i+1]-=h;c+=h;		
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

int N, M, K;
typedef pair<int, int> P;
struct Edge {
	int to, cost;
	Edge();
	Edge(int a, int b) { to = a, cost = b; }
};
vector<vector<Edge>> e;
vector<int> start;
int d[3000];

void djk() {
	for (int i = 0; i < N; i++)d[i] = 1000000000;
	priority_queue<P, vector<P>, greater<P>> pq;
	for (int i = 0; i < K; i++) {
		pq.push(P(0, start[i]));
		d[start[i]] = 0;
	}
	while (pq.size()) {
		auto tmp = pq.top(); pq.pop();
		if (tmp.first > d[tmp.second])continue;
		for (int i = 0; i < e[tmp.second].size(); i++) {
			auto next = e[tmp.second][i];
			if (d[next.to] > d[tmp.second] + next.cost) {
				d[next.to] = d[tmp.second] + next.cost;
				pq.push(P(d[next.to], next.to));
			}
		}
	}
}

int main() {
	cin >> N >> M >> K;
	e.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		e[a].push_back(Edge(b, c));
		e[b].push_back(Edge(a, c));
	}
	for (int i = 0; i < K; i++) {
		int a;
		cin >> a;
		a--;
		start.push_back(a);
	}
	djk();
	double ans = 0;
	for (int i = 0; i < N; i++)ans = max(ans, (double)d[i]);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < e[i].size(); j++) {
			ans = max(ans, (double)(d[e[i][j].to] + d[i] + e[i][j].cost) / 2 + 0.5);
		}
	}
	cout << (int)ans << endl;
	return 0;
}

Measured memory_bytes: 6040
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const ll MOD = pow(10, 9) + 7;
int main (void) {
    int N;

    cin >> N;

    vector<pair<int, int> > v;
    for (int i = 2; i <= N; i++) {
        int cnt = 0;
        for (int j = 2; j <= i; j++) {
            if (i % j == 0) {
                cnt++;
            }
        }
        if (cnt == 1) {
            v.push_back(make_pair(i, 0));
        }
    }


    for (int i = 1; i <= N; i++) {
        for (int j = 0, size = v.size(); j < size; j++) {
            int tmp = i;
            while (tmp % v[j].first == 0) {
                v[j].second++;
                tmp /= v[j].first;
            }
        }
    }

    ll ans = 1;
    for (int i = 0, size = v.size(); i < size; i++) {
        ans = ans * (v[i].second + 1) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N;
	string S;
  	cin >> N >> S;
  
  	int Ans = 0;
  	for(int i = 0; i < N - 2 ; i++){
      if(S.at(i) == 'A'){
      	if(S.at(i+1) == 'B' && S.at(i+2) == 'C'){
          Ans ++;
      	}
      }
    }
  
  cout << Ans << endl;
  	
}


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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 100000000
#define MOD 1000000007

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

int mp[51][51];
bool ok[55];

void fum(ll num){
	REP(i,51)REP(j,51)mp[i][j] = INF;
	REP(i,51)mp[i][i] = 0;
	REP(i,51){
		if(num & (1LL<<i)){
			for(int j = 1;j < 51;j++){
			//	if(num == 32)cout << num << ' ' << j << ' ' << (j%i) << endl;
				mp[j][j%i] = 1;
			}
		}
	}
	REP(k,51)REP(i,51)REP(j,51){
		mp[i][j] = min(mp[i][j],mp[i][k] + mp[k][j]);
	}
}

int main()
{
	ll ans = 0;
	
	for(int i = 50;i > 0;i--)ans |= (1LL << i);
	
	ll n;cin >> n;
	
	vector<ll> A(n);
	REP(i,n)cin >> A[i];
	vector<ll> B(n);
	REP(i,n)cin >> B[i];
	
	fum(ans);
	REP(i,n){
		if(mp[A[i]][B[i]] != INF){
			ok[i] = true;
		}
	}
	
	REP(i,n){
		if(!ok[i]){
			cout << -1 << endl;
			return 0;
		}
	}
		
	for(ll i = 50;i > 0;i--){
		ll tmp = ans & ~(1LL << i);
		if(ans == tmp)continue;
		fum(tmp);
		bool flag = true;
		REP(i,n){
			if(mp[A[i]][B[i]] == INF)flag = false;
		}
		if(flag)ans = tmp;
	}
	
	cout << ans << endl;
		
	
	return 0;
}

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

int main() {
  std::string S;
  std::cin >> S;

  size_t i = 0;
  size_t j = S.size() - 1;
  size_t result = 0;
  while (i < j) {
    if (S[i] != S[j]) result++;
    i++;
    j--;
  }

  std::cout << result;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
void dfs(ll n,vll &color,vector<vector<pll>> &r,ll c,ll now){
  color[now]=c;
  for(int i=0;i<r[now].size();i++){
    if(color[r[now][i].F]!=0) continue;
    else if(r[now][i].S%2==0){
      dfs(n,color,r,c,r[now][i].F);
    }
    else{
      dfs(n,color,r,-c,r[now][i].F);
    }
  }
}
int main(){
  ll n;
  cin>>n;
  vector<vector<pll>> r(n+1,vector<pll> (0));
  rep(i,n){
    ll a,b,c;
    cin>>a>>b>>c;
    r[a].pb(mp(b,c));
    r[b].pb(mp(a,c));
  }
  vll color(n+1,0);
  dfs(n,color,r,1,1);
  for(int i=1;i<=n;i++){
    if(color[i]==1){
      COUT(1);
    }
    else{
      COUT(0);
    }
  }
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main() {
    int h, w; cin >> h >> w;
    char a[h][w];
    rep(i,h)rep(j,w) cin >> a[i][j];

    int ans = 0;
    int num = 0;

    int d[h][w];
    rep(i,h)rep(j,w) d[i][j] = INF;

    queue<P> que;
    rep(i,h)rep(j,w) {
        if (a[i][j]=='#') {
            num++;
            que.push(P(i,j));
            d[i][j] = 0;
        }
    }


    while (!que.empty()) {
        P p = que.front(); que.pop();
        rep(i,4) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if (0<=ny && ny<h && 0<=nx && nx<w && a[ny][nx]!='#' && d[ny][nx]==INF) {
                que.push(P(ny,nx));
                a[ny][nx] = '#';
                num++;
                d[ny][nx] = d[p.first][p.second]+1;
            }
        }
        bool check = false;
        if (num == h*w) check = true;
        if (check) {
            rep(i,h)rep(j,w) {
                chmax(ans, d[i][j]);
            }
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
const int N = 2e5 + 7;

vector<int> conn[N];
int subtree_size[N];
int parent[N];

int dfs(int n) {
	int sz = 1;
	for (auto i : conn[n]) {
		if (i == parent[n])
			continue;
		parent[i] = n;
		sz += dfs(i);
	}
	return subtree_size[n] = sz;
}

ll add(ll a, ll b) {
	return ((a%mod) + (b%mod)) % mod;
}

ll sub(ll a, ll b) {
	return ((a%mod) - (b%mod) + mod) % mod;
}

ll mul(ll a, ll b) {
	return ((a%mod) * (b%mod)) % mod;
}


ll fp(ll b, ll e) {
	if (!e)
		return 1;
	ll ans = fp(b, e / 2);
	ans = mul(ans, ans);
	if (e & 1) {
		ans = mul(b, ans);
	}
	return ans;
}

ll divide(ll a, ll b) {
	return ((a%mod) * fp(b, mod - 2)) % mod;
}



int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		conn[u].push_back(v);
		conn[v].push_back(u);
	}
	dfs(1);
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ll totalSz = 0;
		ll totalProb = 0;
		if (conn[i].size() < 2)
			continue;
		for (auto j : conn[i]) {
			if (j == parent[i])
				continue;
			ll prob = divide(sub(fp(2, subtree_size[j]), 1), fp(2, n));
			//cout << j << " " << subtree_size[j] << endl;
			totalProb = add(totalProb, prob);
			totalSz = add(totalSz, subtree_size[j]);
		}
		if (i > 1) {
			ll prob = divide(sub(fp(2, n - subtree_size[i]), 1), fp(2, n));
			totalProb = add(totalProb, prob);
		}
		totalProb = add(totalProb, divide(1, fp(2, n)));
		ans = add(ans, sub(divide(1, 2), totalProb));
	}
	cout << ans;
}

Measured memory_bytes: 21272
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if((a+b)%3==0||a%3==0||b%3==0)
  {
    cout<<"Possible"<<endl;
  }
  else
  {
    cout<<"Impossible"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int n;
int dist[220];
vvin a;

void bfs(int now){
  queue<int> que;
  que.push(now);
  while(!que.empty()){
   int b=que.front();
    que.pop();
    rep(v,0,n){
      if(a[b][v]==0)continue;
      if(dist[v]!=-1)continue;
      dist[v]=dist[b]+1;
      que.push(v);
    }
  }
  return;
}

int main(){cout<<fixed<<setprecision(20);
		   
           cin>>n;
           a.resize(n,vin(n));
           rep(i,0,n){
            string s;
             cin>>s;
             rep(j,0,n){
              a[i][j]=s[j]-'0'; 
             }
           }
           int fans=0;
           rep(start,0,n){
           rep(i,0,n)dist[i]=-1;
           dist[start]=0;
           bfs(start);
           bool ans=true;
           int mx=0;
           rep(i,0,n){
            int d=dist[i];
             chmax(mx,d);
             rep(j,0,n){
               if(i==j)continue;
               if(dist[j]!=d)continue;
               if(a[i][j]==1)ans=false;
             }
             //cout<<i<<" "<<dist[i]<<endl;
            }
             if(ans)chmax(fans,mx);
           }
           if(fans!=0)cout<<fans+1<<endl;
           else cout<<-1<<endl;
          /* rep(i,0,n){
             rep(j,0,n)cout<<a[i][j];
             cout<<endl;
           }*/
}

Measured memory_bytes: 3804
#  --*-coding:utf-8-*--

MOD = 10**9 + 7

def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x

def modFact(n, mod):
    x = 1

    for i in range(2, n+1):
        x = x*i%mod

    return x


def getModInv(a, b):
    return 1 if (a == 1) else int((1-b*getModInv(b%a, a))/a%b)


def f(X, Y):
    if X*2<Y or Y*2<X or (X+Y)%3 != 0:
        return 0

    N = (X+Y)//3
    K = X - N

    return(modFact(N, MOD)*(getModInv(
        modFact(K, MOD)*modFact(N-K, MOD)%MOD, MOD))%MOD)



def main():
    X, Y = map(int, input().split())
    print(f(X, Y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int A,B,C;
    cin >> A >> B >> C;
    if(B >= C || A+B >= C || A >= C){
        cout << B+C << endl;
    }
    else cout << B+B+A+1 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# @Date    : 2019-06-24 21:15:56
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

import sys
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


n, L = RMI()
arr = [ L + i -1  for i in range(1, n + 1)]
count_0 = arr.count(0)
sums    = sum(arr)
if count_0 == 1: del arr[arr.index(0)]
elif count_0 == 0 and sums >= 1: del arr[arr.index(min(arr))]
elif count_0 == 0 and sums <= -1:del arr[arr.index(max(arr))]
else:pass
print(sum(arr))



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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
int n;
ll t[110];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	rep(i, n)cin >> t[i];
	ll ans = 1;
	rep(i, n) {
		ans = lcm(ans, t[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
    long long X;
    cin >> X;
    
    vector<long long> data(1000);
    
    for(int i=0;i<1000;i++){
        data.at(i)=std::pow(i,5.0);
    }
    
    for(int i=0;i<1000;i++){
        for(int j=0;j<1000;j++){
            if(data.at(i)-data.at(j)==X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    
    for(int i=0;i<1000;i++){
        for(int j=0;j<1000;j++){
            if(data.at(i)+data.at(j)==X){
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  ll n, k;
  cin >> n >> k;
  if (k == 0) cout << n * n << endl;
  else {
    ll ans = 0;
    for (ll b = k + 1; b <= n; b++) {
      ans += (b - k) * floor((double)n / b);
      if (n % b >= k) ans += n % b - k + 1;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#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 h[n];
  rep(i,n){
    cin>>h[i];
  }
  int a=h[0];
  int ans=0;
  rep(i,n){
    if(a<=h[i]){
      ans++;
      a=h[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    rep(i, s.size()){
        cout << "x";
    }
    cout << endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>X(N);
  long long sumf=0;
  long long sums=0;
  for(int i=0;i<N;i++){
    cin>>X.at(i);
    sumf=sumf+X.at(i);
    sums=sums+(X.at(i)*X.at(i));
  }
  long long minmum=100000000000;
  for(int p=0;p<101;p++){
    long long t=N*(p*p)+sums-2*p*sumf;
    minmum=min(t,minmum);
  }
  cout<<minmum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[10][10];
bool a[10];
bool b[10];
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>c[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<(1<<m);j++){
			int cnt=0;
			for(int ii=0;ii<n;ii++){
				a[ii]=0;
				if(i&(1<<ii)){
					a[ii]=1;
				}
			}
			for(int jj=0;jj<m;jj++){
				b[jj]=0;
				if(j&(1<<jj)){
					b[jj]=1;
				}
			}
			for(int ii=0;ii<n;ii++){
				for(int jj=0;jj<m;jj++){
					if(!a[ii]&&!b[jj]&&c[ii][jj]=='#')cnt++;
				}
			}
			if(cnt==k){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3568
def main():
        N,Q = map(int,input().split())
        ab = [list(map(int,input().split())) for _ in range(N - 1)]
        ab.sort()
        
        plus = [0 for _ in range(N)]
        for _ in range(Q):
        	p,x = map(int,input().split())
        	plus[p - 1] += x 

        for a,b in ab:
                plus[b - 1] += plus[a - 1]
        for p in plus:
                print(p)

if __name__ == '__main__':
        main()


Measured memory_bytes: 64204
#include <iostream>
#include <vector>
#include <map>
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M; 
  
  cin >> N >> M;
  
  long long int  A[100010];
  
  for (int i = 0; i < N; ++i) cin >> A[i];
  
  map<long long, long long> nums;
  long long ans = 0;
  
  nums[ans]++;
  for (int i = 0; i < N; ++i) {
	ans += A[i];
	nums[ans % M]++;
  }
  long long res = 0;
  
  for (map<long long, long long>::iterator it = nums.begin(); it != nums.end(); it++) {
    
	res += it->second * (it->second - 1) / 2;
  }
  
  cout << res << endl;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
    static String target;
    static String base;
    static int[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        base = sc.next();
        target = sc.next();
        dp = new int[base.length()][target.length()];
        for (int[] arr : dp) {
            Arrays.fill(arr, Integer.MIN_VALUE);
        }
        System.out.println(getLength(0, 0));
    }
    
    static int getLength(int idx, int tidx) {
        if (tidx >= target.length()) {
            return base.length() - idx;
        }
        if (idx >= base.length()) {
            return target.length() - tidx;
        }
        if (dp[idx][tidx] >= 0) {
            return dp[idx][tidx];
        }
        if (base.charAt(idx) == target.charAt(tidx)) {
            return dp[idx][tidx] = getLength(idx + 1, tidx + 1);
        }
        return dp[idx][tidx] = Math.min(getLength(idx + 1, tidx + 1) + 1, Math.min(getLength(idx, tidx + 1) + 1, getLength(idx + 1, tidx) + 1));
    }
}


Measured memory_bytes: 31972
X,N=map(int,input().split())
L=list(map(int,input().split()))
ans=10000
for i in range(100):
    if X-i in L:
        pass
    else:
        ans=X-i
        break
    if X+i in L:
        pass
    else:
        ans=X+i
        break

print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
void test()
{
    int n;
    cin >> n;
    vector<vector<int>> buka;
    buka.resize(n);
    for (int i = 0; i < n - 1; ++i)
    {
        int a;
        cin >> a;
        buka.at(a - 1).push_back(1);
    }
    for (int i = 0; i < buka.size(); ++i)
    {
        cout << buka.at(i).size() << endl;
    }
}

int main()
{
    test();
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif


void Main() {
    ll N; cin >> N;
    vector<ll> d(N);
    rep(i, N){cin >> d.at(i);}
    ll ans = 0;
    rep(i, N){
        rep(j, N){
            if (i >= j){continue;}
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if( (a + b) > (c + d)){
    cout << "Left" << endl;
  }
  else if((a + b) < (c + d)){
    cout << "Right" << endl;
  }
  else if((a + b) == (c + d)){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = GetInput_string()[0];
            var T = GetInput_string()[0];

            int addIndex = 0;
            int maxCount = 0;
            while (addIndex + T.Length <= S.Length)
            {
                var count = 0;
                for(int i = 0; i < T.Length; i++)
                {
                    if (S[i + addIndex] == T[i]) count++;
                }
                if (maxCount < count) maxCount = count;
                addIndex++;
            }
            var result = T.Length - maxCount;
            Console.WriteLine(result);
        }
        
        #region input


        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion
        
    }
}

Measured memory_bytes: 25876
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        x: isize,
        y: isize,
    }
    let mut ans = (y.abs() - x.abs()).abs();
    if x + ans == y {
        ans += 0;
    } else if -x + ans == y {
        ans += 1;
    } else if -x - ans == y {
        ans += 1;
    } else if x - ans == y {
        ans += 2;
    }

    println!("{}", ans);
}


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

int n,wt;
long int w[100],v[100],memo[100][100000];
bool d[100][100000]={false};
long int wh(int i,long int lw);

int main(void){
  long int i,ans;
  cin >> n >> wt;
  for (i=0;i<n;i++) cin >> w[i] >> v[i];
  ans=wh(n-1,wt);
  cout << ans << '\n';
  return 0;
}

long int wh(int i,long int lw){
  long int a=0,b,ret;
  if (i==0) return (lw<w[0])? 0:v[0];
  if (d[i][lw]) return memo[i][lw];
  if (lw>=w[i]) a=wh(i-1,lw-w[i])+v[i];
  b=wh(i-1,lw);
  ret=(a>b)? a:b;
  memo[i][lw]=ret;
  d[i][lw]=true;
  return ret;
}

Measured memory_bytes: 86272
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
string S;
int Q;
int qtype[20202];
int i[20202], l[20202], r[20202];
char c[20202];
set<int> char_pos[30];
vector<int> ans;

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

    for (int i = 0; i < N; i++)
    {
        char si = S[i];
        char_pos[si - 'a'].insert(i);
    }

    rep(j, 0, Q)
    {
        cin >> qtype[j];
        if (qtype[j] == 1)
        {
            int i;
            char c;
            cin >> i >> c;
            i--;
            char si = S[i];
            char_pos[si - 'a'].erase(i);
            S[i] = c;
            char_pos[c - 'a'].insert(i);
        }
        else
        {
            ll l, r;
            cin >> l >> r;
            l--;

            int ans = 0;
            rep(k, 0, 26)
            {
                auto it = char_pos[k].lower_bound(l);
                if (it != char_pos[k].end() && *it < r)
                    ans++;
            }
            cout << ans << endl;
        }
    }
}


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

ll mod=998244353;

struct rangeSumPointQuery
{
    int size;
    vector <ll> sums;

    void build(int n)
    {
        size=1;
        while (size<n) size*=2;
        sums.assign(2*size, 0);
    }

    void addrec(int l, int r, ll val, int x, int lx, int rx)
    {
        if (lx>=r || rx<=l) return;
        if (lx>=l && rx<=r)
        {
            sums[x] = (sums[x]+val)%mod;
            return;
        }
        int mid=(lx+rx)/2;
        addrec(l,r,val, 2*x+1, lx, mid);
        addrec(l,r,val, 2*x+2, mid, rx);
    }

    void add(int l, int r, ll val)
    {
        addrec(l,r,val, 0, 0, size);
    }

    ll getrec(int index, int x, int lx, int rx)
    {
        if (rx-lx==1) 
        {
            return sums[x];
        }
        int mid=(lx+rx)/2;
        if (mid>index) return (sums[x]+getrec(index, 2*x+1, lx, mid))%mod;
        return (sums[x]+getrec(index, 2*x+2, mid, rx))%mod;
    }

    ll get(int index)
    {
        return getrec(index, 0, 0, size);
    }

};


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,K;
    cin >> N >> K;
    rangeSumPointQuery S;
    S.build(N+1);
    vector < pair <ll, ll> > X(K);
    loop(i,0,K) cin >> X[i].first >> X[i].second;
    S.add(1,2, 1);
    //cout << S.get(1) << "\n";
    for (int i=1; i<=N; ++i)
    {
        ll cur=S.get(i);
        loop(j,0,K)
        {
            if (i+X[j].first > N) continue;
            S.add(i+X[j].first, min(i+X[j].second, N)+1, cur);
        }
    }
    cout << S.get(N) << "\n";
    return 0;
}

Measured memory_bytes: 7424
list=[chr(i) for i in range(97, 97+26)]
S=input()
S=set(S)
A=[x for x in S]
A=sorted(A)
if len(A)<26:
    A+="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
for i in range(26):
    if A[i] == list[i]:
        pass
    else:
        print(list[i])
        exit()
print("None")


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

int main(){
  int cnt = 0;
  while(true){
    cnt++;
    int x; cin >> x;
    if(x == 0) break;
    cout << "Case " << cnt << ": " << x << endl;
  }
  return 0;
}



Measured memory_bytes: 3008
use std::io;
use std::str::FromStr;

fn drawrectangle(h: i32, w: i32) {

    for _ in 0..h {
        for _ in 0..w {
            print!("#");
        }
        println!("");
    }
    println!("");
}

fn main() {

    for i in 1.. {
        let stdin = io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).ok();
        let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());

        let h = it.next().unwrap() as i32;
        let w = it.next().unwrap() as i32;

        if w == 0 && h == 0 {
            break;
        }
        else {
            drawrectangle(h, w);
        }
    }
}



Measured memory_bytes: 5024
#include<iostream>
using namespace std;
int main(){
        int N,M;
        cin>>N>>M;
        int num[51]={0};
        int H[100];
        for(int i=0;i<M;i++){
                cin>>H[2*i]>>H[2*i+1];
        }
        for(int i=0;i<2*M;i++){
                num[H[i]]++;
        }
        for(int i=1;i<=N;i++){
                cout<<num[i]<<endl;
        }
}

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

int main() {
  string S;
  cin>>S;
  int s=0,t=0;
  int n=S.size(),cnt=0;
  if(S[0]=='S') s++;
  for(int i=1;i<S.size();i++){
    if(S[i-1]=='T'&&S[i]=='S'){
      cnt+=min(s,t);
      s-=min(s,t)-1;t=0;
      continue;
    }
    if(S[i]=='T') t++;
    else s++;
  }
  cnt+=min(s,t);
  cout<<n-2*cnt<<endl;
}



Measured memory_bytes: 640