akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n, k;
	cin >> n;
	cin >> k;
	int ans = 1;
	while (n--) {
		if (ans < k) {
			ans *= 2;
		}
		else {
			ans += k;
		}
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ff;
typedef long long unsigned ul;
#define pf printf
#define sf scanf
#define mp make_pair
#define pb push_back
#define pfds(a) pf("%lld ",(a))
#define pfdn(a) pf("%lld\n",(a))
#define pffs(a) pf("%Lf ",(a))
#define pffn(a) pf("%Lf\n",(a))
#define pfss(a) pf("%s ",(a))
#define pfsn(a) pf("%s\n",(a))
#define scd(a) sf("%lld",&(a))
#define scf(a) sf("%Lf",&(a))
#define scs(a) sf("%s",(a))
#define scc(a) sf("%c",&(a))
#define FORF(i,a) for(ll (i)=0;(i)<(a);(i)+=1)
#define FORD(i,a) for(ll (i)=(a);(i)>=0;(i)-=1)
#define FORF2(i,a,b) for(ll (i)=(a);i<(b);(i)+=1)
#define FORD2(i,a,b) for(ll (i)=(a);i>=(b);(i)-=1)
#define max3(a,b,c) a>b?a>c?a:c:b>c?b:c
#define min3(a,b,c) a<b?a<c?a:c:b<c?b:c
void to_binary(int n){ if(!n) return; to_binary(n>>1); printf("%d",n&1 ? 1 : 0); }
const ul mod = 1e9+7;
const int size = 1e3 + 3;
int main()
{
	ll n;scd(n);
	ll a=n/10,b=n%10;
	if(a==9 || b==9)
		pfsn("Yes");
	else
		pfsn("No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>

using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
  return 0;
}


Measured memory_bytes: 256
p,q= input().split()
a,b =(int(p), int(q))
a_list = []
count_row = 0
b_h ='.'*b

for i in range(a):
    c = input()
    
    if c == b_h:
        count_row+=1
    else:
        a_list.append(c)

ans_list=[]
for i in range(b):
    count_clm = 0
    
    for j in range(a-count_row):
        if a_list[j][i] == '.':
            count_clm+=1
    
    
        if count_clm == (a-count_row):        
            ans_list.append(i)



for j in range(a-count_row):
    total=''
    for i in range(b):
        if i in ans_list:
            ds = 0
        else:
            total +=a_list[j][i]
            
    print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define RFOR(i,c) for(auto i=(c).rbegin();i!=(c).rend();++i)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int w, h;
int Map[30][30];
int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};

int check(int x, int y, int rest){
	int ans = -1;
	if(rest == 0) return -1;
	REP(i, 4){
		int k=1;
		if(Map[y+d[i][1]][x+d[i][0]] == 1) continue;
		for(;!Map[y+d[i][1]*k][x+d[i][0]*k];k++);
		if(Map[y+d[i][1]*k][x+d[i][0]*k] == -1) continue;
		if(Map[y+d[i][1]*k][x+d[i][0]*k] == 3) return rest-1;
		if(Map[y+d[i][1]*k][x+d[i][0]*k] == 1){
			Map[y+d[i][1]*k][x+d[i][0]*k] = 0;
			ans = max(ans, check(x+d[i][0]*(k-1), y+d[i][1]*(k-1), rest - 1));
			Map[y+d[i][1]*k][x+d[i][0]*k] = 1;
		}
	}
	return ans;
}

main(){
	while(cin >> w >> h, w){
		memset(Map, -1, sizeof(Map));
		int sx, sy;
		REP(i, h)REP(j, w){
			int t;
			cin >> Map[i+1][j+1];
			if(Map[i+1][j+1] == 2){
				Map[i+1][j+1] = 0;
				sx = j+1;sy = i+1;
			}
		}
		int res = check(sx, sy, 10);
		cout << (res==-1?res:10-res) << endl;
	}
	return 0;
}

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

int main()
{
  int n;
  int s,g;
  int add;
  cin>>n;
  while(n-->0){
    cin>>s>>g;
    add=1;

    if(s<=g){
      cout<<s;
      while(s!=g){
	s+=add;
	cout<<" "<<s;
      }
    }else{
      if(s<=5)add=-1;
      cout<<s;
      while(s!=g){
	if(s==9){
	  s=6;
	  add=-1;
	}
	if(s==0){
	  s=0;
	  add=1;
	}
	s+=add;
	cout<<" "<<s;
      }
    }
    puts("");
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
int main(void) {
    int len, match, i, j;
    char tmp, text[110], pattern[110], ring[110];
    scanf("%s", text);
    len = strlen(text);
    tmp = getchar();
    scanf("%s", pattern);
    for (i = 0; i < len; i++) {
        for (j = 0; j < len; j++) {
            ring[j] = text[(i + j) % len];
        }
        match = strstr(ring, pattern);
        if (match != '\0') {
            match = 1;
            break;
        }
    }
    if (match == 1) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
 
#define X first
#define Y second
#define N 220
#define M 11
 
typedef long long ll;
const int Mod = 1000000007;
const int INF = 1e9 + 1;

struct Edge
{
	int u, v, cap;
	Edge(int _u = 0, int _v = 0, int _cap = 0){u = _u, v = _v, cap = _cap;}
};

vector<int> E[N];
vector<Edge> e;

int edgecnt;
int cur[N], d[N];
char s[N][N];

void Add_Edge(int u, int v, int cap)
{
	//cout << u <<" " <<v <<" " << cap << endl;
	e.push_back(Edge(u, v, cap));
	e.push_back(Edge(v, u, 0));
	E[u].push_back(edgecnt++);
	E[v].push_back(edgecnt++);
}

bool BFS(int S, int T, int n)
{
	queue<int> Q;
	Q.push(T);
	for (int i = 0; i <= n; ++i) d[i] = INF;
	d[T] = 0;
	
	while (!Q.empty())
	{
		int x = Q.front(); Q.pop();
		//cout << x << endl;
		for (int i = 0; i < E[x].size(); ++i)
		{
			int y = e[E[x][i]].v;
			//cout << y <<" " << e[E[x][i] ^ 1].cap << endl;
			if (!e[E[x][i] ^ 1].cap) continue;
			if (d[y] == INF) 
			{
				d[y] = d[x] + 1;
				Q.push(y);
			}
		}
	}
	//cout << "d[S] = " << d[S] << endl;
	return d[S] != INF;
}

int DFS(int x, int T, int lim)
{
	if (x == T || !lim) return lim;
	
	int flow = 0, tmp;
	for (int &i = cur[x], y; i < E[x].size(); ++i)
	{
		y = e[E[x][i]].v;
		if (d[y] + 1 != d[x] || !e[E[x][i]].cap) continue;
		tmp = DFS(y, T, min(lim, e[E[x][i]].cap));
		if (tmp)
		{
			e[E[x][i]].cap -= tmp;
			e[E[x][i] ^ 1].cap += tmp;
			flow += tmp;
			lim -= tmp;
			if (!lim) break;
		}
	}
	
	return flow;
}

int MaxFlow(int S, int T, int n)
{
	int flow = 0;
	while (BFS(S, T, n))
	{
		memset(cur, 0, sizeof(cur));
		flow += DFS(S, T, INF);
	}
	
	return flow;
}

int main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i)
    {
    	scanf("%s", s[i] + 1);
    	for (int j = 1; j <= m; ++j)
    	{
    		if (s[i][j] == 'o') Add_Edge(i, j + n, 1), Add_Edge(j + n, i, 1);
    		if (s[i][j] == 'S') Add_Edge(0, i, INF), Add_Edge(0, j + n, INF);
    		if (s[i][j] == 'T') Add_Edge(i, n + m + 1, INF), Add_Edge(j + n, n + m + 1, INF);
		}
	}
	int res = MaxFlow(0, n + m + 1, n + m + 1);
	if (res >= INF) res = -1;
	printf("%d\n", res); 
    

    return 0;
}


Measured memory_bytes: 1200
n, y = map(int, input().split())
ans = [-1, -1, -1]
flg = False

for i in range(0, n+1):
    if flg == True:
        break
    for j in range(0, n+1):
        if flg == True:
            break
        if n-i-j < 0:
            break
        if (10000*i + 5000*j + 1000*(n-i-j)) == y:
            ans = [i, j, (n-i-j)]
            flg = True

print(ans[0], ans[1], ans[2])


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

int main(){
    string s;
    cin>>s;
    int len=s.size();
    int cnt=0;
    bool flag=true;;
    if(s[0]!='A'){
        flag=false;
    }
    for(int i=1;i<len;i++){
        if(isupper(s[i])){
            if(i==1||i==len-1||s[i]!='C'){
                flag=false;
            }
            cnt++;
        }
    }
    if(cnt!=1||!flag)cout<<"WA"<<endl;
    else cout<<"AC"<<endl;
}

Measured memory_bytes: 3604
// AOJ 1245: Gap
// 2017.10.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char r, c; } T;
#define QMAX 70000
typedef struct { char tbl[4][8]; int s; } Q;
Q q[QMAX+3]; int top, end;
char tbl[4][8];

#define HASHSIZ 120011
unsigned hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int insert(unsigned x)
{
	unsigned *p = hash + x % HASHSIZ;
	while (*p) {
		if (*p == x) return 1;
		if (++p == hashend) p = hash;
	}
	*p = x;
	return 0;
}

unsigned check(char tbl[4][8])
{
	int i, j, k, f;
	unsigned x;

	for (x = 0, f = 0, k = 11, i = 0; i < 4; i++, k += 10) {
		for (j = 1; j < 7; j++) {
			x <<= 1, x += tbl[i][j];
			if (tbl[i][j] != k+j) f = 1;
		}
		x <<= 1, x += tbl[i][7];
	}
	if (f) return x;
	return 0;
}

int main()
{
	int t, i, j, r, c, r2, c2, v, s, ans;
	char tmp[4][8];
	unsigned x;

	scanf("%d", &t);
	while (t-- > 0) {
		for (r = 0; r < 4; r++) for (c = 1; c < 8; c++) scanf("%d", &v), tbl[r][c] = v;
		// initial layout
		for (r = 0; r < 4; r++) {
			tbl[r][0] = 10*r + 11;
			for (c = 1; c < 8; c++)	if (tbl[r][c] % 10 == 1) tbl[r][c] = 0;
		}

		memset(hash, 0, sizeof(hash));
		if ((x = check(tbl)) == 0) { puts("0"); continue; }
		insert(x);
		ans = -1, top = 0, end = 1;
		memcpy(q[0].tbl, tbl, sizeof(tbl)), q[0].s = 0;

		while (top < end) {
			for (i = 0; i < 4; i++) {
				memcpy(tmp, q[top].tbl, sizeof(tbl)), s = q[top].s + 1;
				for (j = 0, r = 0; r < 4; r++) for (c = 1; c < 8; c++) {
					if (tmp[r][c] == 0) { if (j++ == i) goto next1; }
				}
		next1:
				v = tmp[r][c-1];
				if (v == 0 || v % 10 == 7) continue;
				v++;
				for (r2 = 0; r2 < 4; r2++) for (c2 = 1; c2 < 8; c2++) {
					if (tmp[r2][c2] == v) {
						tmp[r2][c2] = 0, tmp[r][c] = v;
						goto next2;
					}
				}
		next2:
				if ((x = check(tmp)) == 0) { ans = s; goto done; }
				if (insert(x)) continue;
				memcpy(q[end].tbl, tmp, sizeof(tbl)), q[end].s = s, end++;
			}
			++top;
		}
done:	printf("%d\n", ans);
	}
 	return 0;
}

Measured memory_bytes: 4520
def resolve_b():
    n = input()
    l = map(int, input().split())
    c = 0
    even_list = [i for i in l if i % 2 == 0]
    if len(even_list) == 0:
        print("APPROVED")
    else:
        for e in even_list:
            if e % 3 == 0 or e % 5 == 0:
                c+=1
        if c == len(even_list):
            print("APPROVED")
        else:
            print("DENIED")
resolve_b()

Measured memory_bytes: 3064
// C++ program for implementation of Ford Fulkerson algorithm 
#include <iostream> 
#include <limits.h> 
#include <string.h> 
#include <queue> 
#include <iostream> 
#include <set> 
#include <iterator> 

using namespace std; 
int count=0;
int jum,s;
int totalsum=3;

void dfs(int lvl,int k,int tot,int num){
if(lvl>3||num>tot)
return ;
else if(lvl==2){
  int sisa=tot-num;
if(sisa>=0 && sisa<=jum){
    count++;
    }
}else{
for(int i=0;i<=jum;i++){
dfs(lvl+1,i,tot,num+i);
}
}

}

int main(){
cin>>jum>>s;
dfs(0,-1,s,0);
cout<<count;
}

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

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int n,k;
    cin>>n>>k;
    if(k > (n-1)*(n-2)/2){
        cout<<-1<<endl;
        return 0;
    }

    vector<P> edge;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            edge.push_back(P(i,j));
        }
    }
    vector<P> ans;
    int cnt = 0;
    for(int i = 0; i < edge.size(); i++){
        if(edge[i].second!=n && cnt<k){
            cnt++;
        }else{
            ans.push_back(edge[i]);
        }
    }
    cout<<ans.size()<<endl;
    for(int i = 0; i < ans.size(); i++){
        cout<<ans[i].first << " " << ans[i].second<<endl;
    }

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        sc.close();

        if(a > b){ 
            System.out.print("0");
            return;
        }

        if(n==1){
            if(a != b){
                System.out.print("0");
                return;
            }else{
                
            }
        }

        System.out.print((n-1)*b + a - (n-1)*a - b + 1);
    }
}

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

int main(){
  int N,K,sum=0;
  cin >> N >> K;
  vector<int> x(N);
  rep(i,N){
    cin >> x.at(i);
  }
  rep(i,N){
    int a=0,b=0;
    a = x.at(i)*2;
    b = abs(x.at(i)-K)*2;
    sum += min(a,b);
  }
  cout << sum << endl;
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        n:usize,
        v:[usize;n],
    }
    let mut v = v;
    let mut ans = 0;
    loop {
        if v.iter().all(|&x| x % 2 == 0 ) {
            ans += 1;
            v = v.iter().map(|&x| x / 2).collect::<Vec<usize>>();
        } else {
            break;
        }
    }
    println!("{}",ans);
}

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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;


const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;

int sb(string s) {
    int b = 0;
    rep(i, s.size() - 1) {
        if (s[i] != s[i + 1]) b++;
    }
    return b;
}
signed main() {
    int n;
    cin >> n;
    int k;
    cin >> k;
    string S;
    cin >> S;

    int b = sb(S);
    b = max(0, b - 2 * k);

    ans = n - b - 1;
    print(ans);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,t=0,j=0,answer=100001;
    int w[101];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> w[i];
        t+=w[i];
    }
    for(int i=0;i<n;i++){
        j+=w[i];
        if(abs(j-(t-j))<answer){
            answer=abs(j-(t-j));
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,k,m,ans;
int a[N],dp[N];
bool vis[N];

inline int solve(int x){
	if(vis[x]) return dp[x];
	vis[x]=1;
	dp[x]=exp(k,(a[x]+1)/2);
	for(int i=1;i<x;i++)
		if(a[x]%a[i]==0) ch(dp[x],mod-solve(i));
	if(a[x]&1) ch(ans,(ll)dp[x]*a[x]%mod);
	else ch(ans,(ll)dp[x]*a[x]/2%mod);
//	dprintf("%d %d\n",a[x],dp[x]);
	return dp[x];
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	read(n,k);
	for(int i=1;i*i<=n;i++)
		if(n%i==0){
			a[++m]=i;
			if(n/i!=i) a[++m]=n/i;
		}
	sort(a+1,a+m+1);
	solve(m);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	result := 1000000
	for i := 1; i < N; i++ {
		A, B, t := i, N-i, 0
		for ; A != 0; A /= 10 {
			t += A % 10
		}
		for ; B != 0; B /= 10 {
			t += B % 10
		}
		if result > t {
			result = t
		}
	}
	fmt.Println(result)
}


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

const int MAX = 110000;
int dp[MAX];

int main(){
    int n; cin >> n;
    for(int i = 0; i < MAX; ++i) dp[i] = -1;
    dp[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int pow6 = 1; v + pow6 <= n; pow6 *= 6){
            if(dp[v+pow6] == -1){
                dp[v+pow6] = dp[v] + 1;
                que.push(v+pow6);
            }
        }
        for(int pow9 = 1; v + pow9 <= n; pow9 *= 9){
            if(dp[v+pow9] == -1){
                dp[v+pow9] = dp[v] + 1;
                que.push(v+pow9);
            }
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 768
A, B, AB, X, Y = map(int,input().split())
AB *= 2

ans = 10**18
for i in range(max(X,Y)+1):
    cost = i * AB
    if i < X:
        cost += A * (X-i)
    if i < Y:
        cost += B * (Y-i)
    ans = min(ans, cost)

print(ans)

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

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

	int sum;

	while (x != "0") {

		sum = 0;
		for (unsigned int i = 0; i < x.length(); i++) {
			sum += std::stoi(x.substr(i, 1));
		}

		std::cout << sum << std::endl;
		std::cin >> x;
	}
}

Measured memory_bytes: 3144
#include <iostream>

using namespace std;

void solve();
int N,x,y,b,p;

int main()
{
	cin>>N;
	for (int i=0; i<N; i++) {
		cin>>x>>y>>b>>p;
		solve();
	}
}

void solve()
{
	int ans,c1=x*b+y*p,c2=0.8*(x*max(5,b)+y*max(2,p));
	ans=min(c1,c2);
	cout<<ans<<endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;

int main()
{
    char a[200050];
    char c[200050];
    cin>>a;
    cin>>c;
    int sum=0;
    int n=strlen(a);
    for(int i=0;i<n;i++)
    {
        if(a[i]!=c[i])
        {
            sum++;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll N, P;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while (cin >> N >> P) {
        ll ans = 1;
        for (ll i=2;i*i<=P;i++) {
            int c = 0;
            while (P % i == 0) {
                P /= i;
                c ++;
            }
            REP(j, c / N) ans *= i;
        }
        if (N == 1) ans *= P;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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; }
// template end

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c;
    in >> a >> b >> c;

    if(b - a == c - b){
        out << "YES" << endl;
    }else{
        out << "NO" << endl;
    }
}


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

using namespace std;

typedef long long ll;

#define MOD 998244353
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);


ll arr[100001];
bool vis[100001];
ll lvl[100001];



ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}


/*const int N=200000;

ll fac[N+1];
ll inv[N+1];
ll p=998244353;

ll c(ll a, ll b,ll m)
{
  if(a<b)return 0;
  return (fac[a]*inv[b]%m)*(inv[a-b])%m;
}

void fill()
{
inv[0]=1;
fac[0]=1;

for(int i=1;i<=N;i++)
{
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

}
*/
//ld dp[2001][2001];


ll bs(ll t)
{
  if(t==1)return 1;
  ll l=1,r=100000,m;
  ll ans=0;
  while(l<=r)
  {
    m=(l+r)/2;
    ll temp=m*(m+1)/2;
    if(temp>t)r=m-1;
    else 
    {
      l=m+1;
      ans=max(ans,m);
    }
  }
  return ans;
}


int main()
{  fast

ll n;cin>>n;

vl a;
ll x=n;

if(n==2||n==3)
{
  cout<<1;
  return 0;
}


ll ans=0;

for(ll i=2;i*i<=n;i++)
{
  if(x%i==0)
  {
    ll cnt=0;
       while(x%i==0)
       {
        cnt++;
        x/=i;
       }
       
        
       ans+=bs(cnt);
     //  if(cnt==1)cout<<bs(cnt);
  }
  if(x==1)break;
}

if(x!=1)ans+=1;

cout<<ans<<"\n";



 return 0;

}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

int main()
{
	int i=-1;
	char str[1024];
	gets(str);
	while(i++!=strlen(str))if('`'<str[i]&&str[i]<'{')str[i]-=' ';
	printf("%s\n",str);
	return 0;
}

Measured memory_bytes: 520
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const int maxn = int(2e5)+5;

int A[maxn];

int main(void)
{
	int n;
	scanf("%d", &n);
	for(int i = 0;i < n;i++) scanf("%d", &A[i]);
	sort(A, A+n);

	int res = 0;
	for(int i = 0;i < n;i++)
	{
		if(fabs(A[n-1]/2.0-A[i]) < fabs(A[n-1]/2.0-res)) res = A[i];
	}
	printf("%d %d\n", A[n-1], res);
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int k = sc.nextInt();
        int n = (int) Math.pow(2, m);
        int xor = 0;
        for (int i = 0; i < n; i++) xor = xor^i;
        xor = xor^k;
        if(k == 0){
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++) {
                sb.append(i).append(" ");
            }
            for (int i = n -1; i >= 0; i--) {
                sb.append(i).append(" ");
            }
            System.out.println(sb.toString());
        }else if(n <= k || xor != k) {
            System.out.println(-1);
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++) {
                if(i != k) sb.append(i).append(" ");
            }
            sb.append(k).append(" ");
            for (int i = n -1; i >= 0; i--) {
                if(i != k) sb.append(i).append(" ");
            }
            sb.append(k);
            System.out.println(sb.toString());
        }
        sc.close();
    }

}


Measured memory_bytes: 39164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, k;
    cin >> n >> k;
    Mint<> ans = 0;
    Mint<> suml = 0, sumr = 0;
    rep(i, n + 1) {
        suml += i;
        sumr += n - i;
        if(i + 1 >= k){
            ans += sumr - suml + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int main(){
    int k;
    string s;
    cin >> k >> s ;
    vs t(k+3);
   
   if(s.size() <= k){
       cout << s << endl;
   }else{
       rep(i,k) t.at(i) = s.at(i);
       rep(i,3) t.at(k+i) = '.';
       rep(i,k+3) cout << t.at(i);
   }

 return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>
#include <math.h>

#define max 4

int* sortMaxmin(int*, int);
int* sortMinmax(int*, int);

int main()
{
    int i;
    char s[max];
    
    scanf("%s", s);
    
    if (s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) {
        printf("Yes");
        return 0;
    } else if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]){
        printf("Yes");
        return 0;
    } else if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[2]){
        printf("Yes");
        return 0;
    } else{
        printf("No");
        return 0;
    }
    
    return 0;
}

int* sortMaxmin(int *a, int b)
{
    int i, j, tmp;
    for(i=0; i<b; i++){
        for (j=i+1; j<b; j++) {
            if(a[i]>a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    return a;
}

int* sortMinmax(int *a, int b)
{
    int i, j, tmp;
    for(i=0; i<b; i++){
        for (j=i+1; j<b; j++) {
            if(a[i]<a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    return a;
}



Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define int long long
inline int in() {int32_t x ; scanf("%d",&x) ; return x ; }
inline string getStr() {char ch[200000] ; scanf("%s",ch) ; return ch ; }
inline char getCh() {char ch ; scanf(" %c",&ch) ; return ch;}
template<class P, class Q> inline P smin(P &a, Q b) { if (b < a) a = b; return a; }
template<class P, class Q> inline P smax(P &a, Q b) { if (a < b) a = b; return a; }
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 10;
const int MA_LG = 21;
const int base = 29;
vector< pair<int,int> > g[MAX_N];
int res[MAX_N];
bool vis[MAX_N];
int32_t main()
{
    int n = in() , m = in() , source = in();
    for (int i = 0 ; i < m ; i ++)
    {
        int v = in() , u = in() , w = in();
        g[v].push_back({u,w});
    }
    for (int v = 0 ; v < n ; v ++)
        res[v] = 1e18;
    res[source] = 0;
    priority_queue<pair<int , int >> pq;
    pq.push({0,source});
    res[source] = 0;
    while (!pq.empty())
    {
        int v = pq.top().second;
        int di = -pq.top().first;
        pq.pop();
        if (vis[v] && res[v] <= di) continue;
        vis[v] = true;
        res[v] = di;
        for (int pt = 0 ; pt < g[v].size() ; pt ++)
        {
            int u = g[v][pt].first , w = g[v][pt].second;
            if (res[u] > w + di)
            {
                if (vis[u] && w + di < 0)
                {
                    cout << "NEGATIVE CYCLE\n";
                    exit(0);

                }
//                res[u] = w + di;
                pq.push({-w-di , u});
            }
        }
    }
    for (int i = 0 ; i < n ; i ++)
    {
        if (res[i] >= 1e18)
        {
            cout << "INF\n";
        }else
        cout << res[i] << "\n";
    }
    
}

Measured memory_bytes: 21724
#line 1 "main_e.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 n;
  std::cin>>n;

  using P=std::pair<i64,i64>;

  std::vector<P> points(n);

  for(auto&& e:points)std::cin>>e.first>>e.second;

  i64 ans=0;

  P d[4] = { {1,1},{1,-1},{-1,1},{-1,-1}};

  constexpr i64 INF=1e10;

  rep(di,0,4){
    i64 max=-INF,min=INF;
    rep(i,0,n){
      i64 val=d[di].first*points[i].first+d[di].second*points[i].second;
      chmax(max,val);
      chmin(min,val);
    }

    chmax(ans,max-min);
  }

  std::cout<<ans<<"\n";
  
  return 0;
}


Measured memory_bytes: 6348
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):

    min_ = min(a) + min(b)
    for i in range(M):
        i_ = a[x[i]-1] + b[y[i]-1] - c[i]
        if i_ < min_:
            min_ = i_

    print(min_)
    return


# 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24612
use std::cmp::max;
use std::io::{Read, StdinLock};
use std::str::{from_utf8, FromStr};
use std::vec::Vec;

struct StdinReader<'a> {
    reader: StdinLock<'a>,
}

impl<'a> StdinReader<'a> {
    pub fn new(reader: StdinLock<'a>) -> StdinReader {
        StdinReader { reader: reader }
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        fn is_whitespace(ch: u8) -> bool {
            ch == 0x20 || ch == 0x0a || ch == 0x0d
        }

        let token: Vec<u8> = self.reader
            .by_ref()
            .bytes()
            .map(|ch| ch.expect("failed to read a byte"))
            .skip_while(|ch| is_whitespace(*ch))
            .take_while(|ch| !is_whitespace(*ch))
            .collect();
        let token_str = from_utf8(&token)
            .unwrap_or_else(|_| panic!(format!("invalid utf8 sequence: {:?}", token)));
        token_str
            .parse()
            .unwrap_or_else(|_| panic!(format!("failed to parse input: {}", token_str)))
    }
}

fn rank(v: &[i64]) -> Vec<usize> {
    let mut indexed: Vec<(usize, &i64)> = v.iter().enumerate().collect();
    indexed.sort_by_key(|t| -t.1);
    indexed.iter().map(|t| t.0).collect()
}

fn solve(n: usize, c: i64, xs: &[i64], vs: &[i64]) -> i64 {
    // value[dir][n] = dir の方向に歩いて n 個の寿司を食べた時の正味栄養価
    let mut value: Vec<Vec<i64>> = vec![vec![0; n + 1]; 2];
    let mut max_value = 0;
    for dir in 0..2 {
        for i in 1..(n + 1) {
            let curr = if dir == 0 { i } else { n - i + 1 };
            let prev = if dir == 0 { curr - 1 } else { curr + 1 };
            value[dir][i] = value[dir][i - 1] + vs[curr] - (xs[curr] - xs[prev]).abs();
            max_value = max(max_value, value[dir][i]);
        }
    }

    let ranking = rank(&value[0]);

    // 半時計回りにm2個食べ、引き返して時計回りにm1個食べる場合
    let mut ri = 0;
    let mut m1 = ranking[ri];
    for m2 in 1..n {
        // 与えられたm2に対して最良のm1を見つける
        while m1 + m2 > n {
            ri += 1;
            m1 = ranking[ri];
        }
        let v = value[0][m1] + value[1][m2] - (c - xs[(n + 1) - m2]);
        max_value = max(max_value, v);
    }

    max_value
}

fn main() {
    let stdin = std::io::stdin();
    let mut reader = StdinReader::new(stdin.lock());

    let n: usize = reader.read();
    let c: i64 = reader.read();

    let (mut xs, mut vs) = {
        let mut a: Vec<(i64, i64)> = Vec::new();
        a.push((0, 0));
        a.push((c, 0));
        for _ in 0..n {
            let x: i64 = reader.read();
            let v: i64 = reader.read();
            a.push((x, v));
        }
        a.sort();
        let xs: Vec<i64> = a.iter().map(|t| t.0).collect();
        let vs: Vec<i64> = a.iter().map(|t| t.1).collect();
        (xs, vs)
    };

    let max_value1 = solve(n, c, &xs, &vs);

    // 反転させる
    xs.reverse();
    vs.reverse();
    for x in xs.iter_mut() {
        *x = c - *x
    }

    let max_value2 = solve(n, c, &xs, &vs);

    println!("{}", max(max_value1, max_value2));
}


Measured memory_bytes: 12232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var kn = Console.ReadLine().Split(' ').Select(q => int.Parse(q)).ToArray();

            var k = kn[0];
            var n = kn[1];

            // 整数配列の入力
            var a = Console.ReadLine().Split(' ').Select(q => long.Parse(q)).ToArray();

            var max = long.MaxValue;

            for(int i = 0; i < n; i++) {
                //時計回り
                var first = a[i];

                var lastIndex = (n - 1 + i) % n;
                var last = a[lastIndex];

                if(last < first) {
                    last += k;
                }

                max = Math.Min(max, Math.Abs(last - first));

                //反時計回り
                first = a[i];

                lastIndex = (i + 1) % n;
                last = a[lastIndex];

                if (last > first) {
                    first += k;
                }

                max = Math.Min(max, Math.Abs(first - last));

            }

            Console.WriteLine(max);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 36580
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        
	        int N = sc.nextInt();
	        int ac =0;
	        int wa =0;
	        int tle=0;
	        int re =0;
	        for(int i=0;i<N;i++) {
	        	String S = sc.next();
	        	if(S.equals("AC")) {
	        		ac++;
	        	} else if(S.equals("WA")) {
	        		wa++;
	        	} else if(S.equals("TLE")) {
	        		tle++;
	        	} else {
	        		re++;
	        	}
	        }
	        
	        System.out.println("AC x " + ac);
	        System.out.println("WA x " + wa);
	        System.out.println("TLE x " + tle);
	        System.out.println("RE x " + re);
		 }
	}

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

int main() {
  int N;
  int64_t c, k;
  cin >> N;
vector<int> veca(N);
  vector<int> vecb(N);
for (int i = 0; i < N; i++) {
  cin >> veca.at(i);
}
  vecb.at(0)=0;
  for (int i = 1; i < N; i++) {
  c=veca.at(i-1)+vecb.at(i-1);
    if(veca.at(i) >= c)
      vecb.at(i)=0;
    else
      vecb.at(i)=c-veca.at(i);
}
  k=0;
  for(int i=0; i<N; i++)
    k+=vecb.at(i);
  cout << k << endl;
}


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

int main()
{
    int n,x=0,mx=0;
    cin>>n;
    string str;
    cin>>str;
    for(int i=0;i<n;i++){
        if(str[i]=='I')
        x=x+1;
        if(str[i]=='D')
        x=x-1;
        mx=max(mx,x);
    }
    cout<<mx;
    
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i, j, n, a[100], v;
  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d", &a[i]);
  for(i=0; i<n; i++){
    v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
  for(j=0; j<n-1; j++) printf("%d ", a[j]);
  printf("%d\n", a[j]);
  }
  return 0;
}

Measured memory_bytes: 1812
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<tuple>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

bool cs[26];

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

	string tmp;
	cin >> tmp;
	for(int i=0;i<tmp.size();i++){
		cs[tmp[i]-'a']=true;
	}

	string s;
	int ans=INF;
	for(char c='a';c<='z';c++){
		if(!cs[c-'a']) continue;
		bool yet=true;
		int cnt=0;
		s = tmp;
		int len=s.size();

		while(yet){
			string ss(100,'A');
			yet=false;
			for(int i=0;i<len-1;i++){
				if(s[i] == c || s[i+1] == c) ss[i]=c;
				else{
					ss[i] = s[i];
					yet=true;
				}
			}
			if(cnt==0 && !yet){
				cout << "0\n";
				return 0;
			}
			cnt++;
			s = ss;
			len--;
		}
		ans = min(ans,cnt);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
enum class Rate {
  GRAY,BROWN,GREEN,SKY,BLUE,YELLOW,ORANGE,RED,ANY
}
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
   val N=readLine()!!.toInt()

   val rates=readLine()!!.split(" ").map(String::toInt).map{
     when(it) {
       in 1..399 ->Rate.GRAY
       in 400..799 -> Rate.BROWN
       in 800..1199 -> Rate.GREEN
       in 1200..1599 -> Rate.SKY
       in 1600..1999 -> Rate.BLUE
       in 2000..2399 -> Rate.YELLOW
       in 2400..2799 -> Rate.ORANGE
       in 2800..3199 -> Rate.RED
       else-> Rate.ANY
     }
   }

   assert(rates.size==N)

   val colors=rates.filter{it!=Rate.ANY}
   val anies=rates.filter{it==Rate.ANY}
   var kinds_min=colors.toSet().size
   val kinds_max=kinds_min+anies.size
  //  kinds_min+=arrayOf(0,anies.size-kinds_min).max()!!
   kinds_min=if(kinds_min==0) {1} else {kinds_min}
  
   println("${kinds_min} ${kinds_max}")
  }
}


Measured memory_bytes: 35976