akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

struct edge { int to, cost; };

const int maxn = 100005;
vector<edge> G[maxn];
ll dist[maxn];
// i から i の (決めた頂点を根とする) 部分木内で一番遠い頂点までの距離
// 根を除く葉の dist は 0
void dfs(int v, int p) {
  for (edge& e : G[v]) {
    if (e.to == p) continue;
    dfs(e.to, v);
    // dfs から上がってきたタイミングで
    chmax(dist[v], dist[e.to] + e.cost);
  }
}

// v を根とする答え
// Dpar : v の親方向の, v から一番遠い頂点と v の距離
int dfs2(int v, int Dpar, int p) {
  vector<pii> d_child;
  d_child.eb(0, -1); // 下で最大2つを取るが, 2つないとき用

  for (edge& e : G[v]) {
    // 親との距離と, 親方向の部分木で一番遠い頂点との距離の和
    if (e.to == p) d_child.eb(Dpar + e.cost, e.to);
    // 部分木の, ある頂点 j への距離と, j と j の部分木内での一番遠い頂点との距離の和
    else d_child.eb(e.cost + dist[e.to], e.to);
  }
  sort(d_child.rbegin(), d_child.rend());
  // sort 後, 最大 2 つ
  int ret = d_child[0].F + d_child[1].F;

  // 同じ部分木内で木の直径が実現されることがある
  for (edge& e : G[v]) {
    if (e.to == p) continue;
    // v と一番遠い方向 f に行かない
    // 2 番手の方に行けば, f の距離を d_p にもつ
    chmax(ret, dfs2(e.to, d_child[d_child[0].S == e.to].F, v));
  }

  return ret;
}

void solve() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b, w;
    cin >> a >> b >> w;
    G[a].eb(edge{b, w});
    G[b].eb(edge{a, w});
  }
  dfs(n / 2, -1);
  cout << dfs2(n / 2, 0, -1) << endl;
}



Measured memory_bytes: 20352
#include<stdio.h>
 int main(void)
 {
     char X,Y;
     int x,y;

     scanf("%c %c",&X,&Y);

     if(X=='A') x=10;
     if(X=='B') x=11;
     if(X=='C') x=12;
     if(X=='D') x=13;
     if(X=='E') x=14;
     if(X=='F') x=15;

     if(Y=='A') y=10;
     if(Y=='B') y=11;
     if(Y=='C') y=12;
     if(Y=='D') y=13;
     if(Y=='E') y=14;
     if(Y=='F') y=15;

     if(x<y)       printf("<\n");
     else if(x>y)  printf(">\n");
     else          printf("=\n");

     return 0;
 }



Measured memory_bytes: 128
import collections
import itertools
import math


N = int(input())


def get_prime_factorized(N):
    R = []
    b, e = 2, 0
    while b ** 2 <= N:
        while N % b == 0:
            N  = N // b
            e += 1
        if e > 0:
            R.append([b, e])
        b, e = b + 1, 0
    if N > 1:
        R.append([N, 1])
    return R


def n_C_r(n, r):
    return int(math.factorial(n) / math.factorial(r) / math.factorial(n-r))


if N > 9:
    L = [l[1]+1 for l in get_prime_factorized(math.factorial(N))]
    L = [[3, 5, 15, 25, 75] if l >= 75 else [3, 5, 15, 25] if l >= 25 else [3, 5, 15] if l >= 15 else [3, 5] if l >= 5 else [3] if l >= 3 else [1] for l in L]
    L = [l for l in L if l != [1]]
    L = list(itertools.chain.from_iterable(L))
    C = collections.Counter(L)

    R = C[75] + n_C_r(C[5], 2) * n_C_r(C[3]-2, 1) + C[25] * (C[3] - 1) + C[15] * (C[5] - 1)

    print(R)
else:
    print(0)


Measured memory_bytes: 3444
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char str[21];
    char tmp[21];
    int i,idx,len;
    idx = 0;
    scanf("%s", str);

    len = strlen(str);

    for( i = len-1 ; i >= 0 ; i-- ){
        if( str[i] == '\0' ){
            break;
        }
        printf("%c", str[i]);
    }
    
    printf("\n");
}



Measured memory_bytes: 2028
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll H,N; cin >> H >> N;
    ll cnt=0;
    vector<ll> A(N); for(int i=0;i<N;i++){cin >> A[i];cnt+=A[i];}
    if(cnt>=H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		String A =scan.next();
		String B =scan.next();

		int numA = Integer.parseInt(A);
		int numB = Integer.parseInt(B);

		int ans = 0;

		for(int i = numA;i <= numB;i++){
			String x = String.valueOf(i);
			if(x.charAt(1) == x.charAt(3) && x.charAt(0) == x.charAt(4)  ){
				ans++;

			}
		}
		System.out.println(ans);




	}


}


Measured memory_bytes: 28116
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



string g;
int y, m, d;

signed main() {
    while (1) {
        cin >> g;
        if (g=="#") break;
        bool h = 0;
        cin >> y >> m >> d;
        if (y<=30) h = 1;
        else if (32<=y) h = 0;
        else {
            if (m<=3) h = 1;
            else if (5<=m) h = 0;
            else {
                if (d==30) h = 1;
                else h = 0;
            }
        }
        if (h) cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
        else cout << "? " << y-30 << ' ' << m << ' ' << d << endl;

    }
}



Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

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

		String a = sc.next();
		String b = sc.next();

		for(int i = 0; i < a.length() + b.length(); i++){
			System.out.print(i%2 == 0 ? a.charAt(i/2) : b.charAt(i/2));
		}
		System.out.println();
    }
}

Measured memory_bytes: 21844
# ランレングス圧縮の考え方で解く
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

# 初期位置が R の人が最終的にどこに向かうかを考える
# 折り返し地点(移動中に訪れる初めての L) までの距離 d と操作回数の偶奇で決まる(今回の操作回数は偶数)
# d が奇数のとき 折り返し地点の 1 つ左側
# d が偶数のとき 折り返し地点
# L も同様に考える

# 連続する R と L をそれぞれグループ化することで折り返し地点を管理しやすくなる
# ランレングス圧縮と同じ


s = S()
n = len(s)
ans = [0] * n
# 初期位置が R の人について
# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算
r_cnt = 0
for i in range(n):
    if s[i] == 'R':
        r_cnt += 1
    else:  # 折り返し地点に来たら計算
        even_num = r_cnt // 2
        odd_num = r_cnt - even_num
        ans[i] += even_num  # 折り返し地点の人数
        ans[i - 1] += odd_num  # 折り返し地点の １ つ左の人数
        r_cnt = 0

# 初期位置が L の人について
# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算
l_cnt = 0
for i in range(n - 1, -1, -1):  # 右側から見ていく
    if s[i] == 'L':
        l_cnt += 1
    else:  # 折り返し地点に来たら計算
        even_num = l_cnt // 2
        odd_num = l_cnt - even_num
        ans[i] += even_num  # 折り返し地点の人数
        ans[i + 1] += odd_num  # 折り返し地点の １ つ左の人数
        l_cnt = 0
print(*ans)


Measured memory_bytes: 10900
#include<iostream>
#include <stdio.h>
using namespace std;
int main(){
  int h,w;
  while(true){
      cin >>h>>w;
      if (h==0 && w==0){
          break;
      }
      for (int i=0; i<h; i++){
          if(i%2==0){
              for(int j=0; j<w; j++){
              if (j%2==0){
                  printf("#");
              }else{
                  printf(".");
              }
            }
          }else{
              for(int j=0; j<w; j++){
              if (j%2==0){
                  printf(".");
              }else{
                  printf("#");
              }
            }

          }
          
          printf("\n");
      }
      printf("\n");
  }
}


Measured memory_bytes: 3020
#include<iostream>
using namespace std;
int main()
{
	int n,i,j,p=0;
	cin>>n;
	int a[n];
	int b[100];

	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<100;i++)
	{
		b[i]=0; 
	}
	
	for(i=0;i<100;i++)
	{
		for(j=0;j<n;j++)
		{
			b[i]+=(a[j]-i)*(a[j]-i);
		}
			
	}
	p=b[0];
	for(i=0;i<100;i++)
	{ 
		if(p>b[i])
		{
			p=b[i];
		}
	}
	cout<<p;
	return 0 ;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
vector<int> x;
int t[200001];

int main(){
  cin >> n;
  REP(i,n){
    int a;
    cin >> a;
    x.push_back(a);
    t[i] = a;
  }
  sort(x.begin(),x.end());
  int mid = x[n/2-1];
  REP(i,n){
    if(mid >= t[i]){
      cout << x[n/2] <<endl;
    }else{
      cout << x[n/2-1] <<endl;
    }
  }
}


Measured memory_bytes: 3828
#include <stdio.h>

int max(int a,int b){
    if(a > b){
        return a;
    }
    else{
        return b;
    }
}

int main(void){
    // Your code here!
    int A,B,C,X,Y;
    int min = 2000000000;
    
    scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
    
    for(int i = 0; i <= 100000; i++){ //ABパターンの有無で別れるので。。別のA,Bのパターンは最初の一回きり
        int tmp = 2*i*C + max(0,X-i)*A + max(0,Y-i)*B; //X > Yならi == XからようやくCのパターンが可能になる。それまでは、条件を満たさない。
        if(tmp < min){
            min = tmp;
        }
    }
    
    printf("%d\n",min);
}


Measured memory_bytes: 1684
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int n = sc.nextInt();
			if(n == 0) {
				break;
			}
			
			int[] a = new int[n];
			double m = 0;
			
			for(int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				m += a[i];
			}
			m /= n;
			
			double v = 0;
			
			for(int i = 0; i < n; i++) {
				v += (a[i]-m) * (a[i]-m);
			}
			v /= n;
			System.out.println(String.format("%f", Math.pow(v, 0.5)));
		}
	}
}


Measured memory_bytes: 31744
#include <stdio.h>

#define WL '#' /* WALL  */
#define BL ' ' /* BLANK */

int main(){
  char g[100][101];
  int d,i,j,k,n,px,py,v,w;
  int dx[]={-1,0,1,0},dy[]={0,-1,0,1};

  scanf("%d\n",&d);
  for(i=0;i<d;i++){
    if(i!=0) printf("\n");
    scanf("%d\n",&n);
    for(j=0;j<n;j++){
      for(k=1;k<n-1;k++) g[j][k]=BL;
      g[j][0]=g[0][j]=g[j][n-1]=WL;
      g[j][n]=0;
    }
    px=py=n-1;
    v=0;w=0;
    while(1){
      if(g[py+dy[v]][px+dx[v]]==BL){
        g[py][px]=WL; px+=dx[v]; py+=dy[v]; w++;
      } else {
        if(g[py][px]==WL || w==2){
          break;
        } else {
          px-=dx[v]; py-=dy[v]; v=(v==3?0:v+1); w=0;
        }
      }
    }
    if(n==2) g[1][1]=BL;
    for(j=0;j<n;j++) printf("%s\n",g[j]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#define INF 10000000000000
using namespace std;

struct edge
{
	int from;
	int to;
	long long int cost;
};

edge es[2005];

long long int d[1005];
int V, E;
bool negative[1005];


void shortest_path(int s)
{
	for (int i = 0; i < V; i++)
		d[i] = INF;
	d[s] = 0;
	for (int j = 0; j < V; j++)
	{
		bool update = false;
		for (int i = 0; i < E; i++)
		{
			edge e = es[i];

			if (d[e.from-1] != INF && d[e.to-1] > d[e.from-1] + e.cost)
			{
				d[e.to-1] = d[e.from-1] + e.cost;
				update = true;
			}
		}
		if (!update)
			break;
	}
}

void find_negative_loop()
{
	for (int i = 0; i < 1005; i++)
		negative[i] = false;

	for (int j = 0; j < V; j++)
	{
		for (int i = 0; i < E; i++)
		{
			edge e = es[i];

			if (d[e.from-1] != INF && d[e.to - 1] > d[e.from - 1] + e.cost)
			{
				d[e.to - 1] = d[e.from - 1] + e.cost;
				negative[e.from - 1] = true;
				if (negative[e.from - 1] == true)
					negative[e.to - 1] = true;
			}
		}
	}
}

int main()
{
	cin >> V >> E;
	for (int i = 0; i < E; i++)
	{
		cin >> es[i].from >> es[i].to >> es[i].cost;
		es[i].cost *= -1;
	}

	shortest_path(0);
	find_negative_loop();

	if (!negative[V - 1])
		cout << -d[V-1] << endl;
	else
		cout << "inf" << endl;


	return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(18);

	int N;
	cin >> N; 
	vector<long long> A(N);
	vin(A);
	long long x = 0;
	rep(i, N){
		x += A.at(i);
		x = x % mod;
	}
	//cout << "x " << x << endl;
	long long y = x * x;
	//cout << "y " << y << endl;
	y = y % mod;
	//cout << "y " << y << endl;
	long long z = 0;
	rep(i, N){
		z += (A.at(i)*A.at(i)) % mod;
		z = z % mod;
	}
	//cout << "z " << z << endl;
	if(y >= z && (y - z) % 2 == 0){
		cout << (y - z) / 2;
		return 0;
	}else{
		while(y < z || (y - z) % 2 == 1){
			y += mod;
		}		
		cout << (y - z) / 2;
		return 0;
	}
}


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

int c[100005];
int ans[100005];
int main(){
    string S;
    cin >> S;
    int N=S.length();
    int i,j;
    int r=0;
    int l=0;
    for(i=1;i<N;i++){
        if(S[i-1]=='R' && S[i]=='R')r++;
        else if(S[i-1]=='L' && S[i]=='L')l++;
        else if(S[i-1]='R' && S[i]=='L'){
            for(j=i-1;j>i-r-2;j--)c[j]=i-1-j;
            r=0;
            }
        else{
            for(j=i-l-1;j<i;j++)c[j]=j-(i-l-1);
            l=0;
        }
    }
    if(S[N-2]='L' && S[N-1]=='L')for(j=N-l-1;j<N;j++)c[j]=j-(N-l-1);
    for(i=0;i<N;i++){
        if(S[i]=='R'){
            if(c[i]%2==0)ans[i+c[i]]++;
            else ans[i+c[i]+1]++;
        }
        else{
            if(c[i]%2==0)ans[i-c[i]]++;
            else ans[i-c[i]-1]++;            
        }
    }
    for(i=0;i<N-1;i++)cout << ans[i] << " ";
    cout << ans[N-1] << endl;
}

Measured memory_bytes: 1408
n, m = map(int, input().split())
pi = []
si = []
for _ in range(m):
    p, s = input().split()
    pi.append(int(p))
    si.append(s)

ac = 0
wa = 0
c = {}
for i in range(m):
    if pi[i] in c.keys():
        if si[i] == 'AC' and c[pi[i]] != float("INF"):
            wa += c[pi[i]]
            ac += 1
            c[pi[i]] = float("INF")
        else:
            c[pi[i]] += 1
    else:
        if si[i] == 'AC':
            c[pi[i]] = float("INF")
            ac += 1
        else:
            c[pi[i]] = 1
print(ac, wa)


Measured memory_bytes: 24632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String S = br.readLine();
		
		int first = (S.length()-1) / 2;
		int second = (S.length()+3) / 2;
		
		String fs = S.substring(0, first);
		String ss = S.substring(second - 1, S.length());
		
		if(fs.equals(ss))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

Measured memory_bytes: 32768
#include<iostream>
#include<string>
using namespace std;
int main()
{

    int x,a,b;
    cin >> x >> a >> b;

    int s,t, sum=0;

    for (int i = 1; i <= x;i++){
        s = 0;
        t = i;
        for(int j = 0; j < 5; j++){
            s += t % 10;
            if(t/10 == 0){
                break;
            }
            else{
                t /= 10;
            }
        }

        if (a<=s && s <= b){
            sum += i;
        }
    }


    cout << sum;
    return 0;

}

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

int main() {
	int k = 1, i = 1, M, N, a;
	vector <int> A;
	cin >> N >> M;
	for (i = 0; i < N; i++) {
		cin >> a;
		A.push_back(a);
		a = 0;
	}
	for (k = 1; k < M+1; k++) {
		for (i = 0; i < N; i++) {
			if (i < N-1) {
				if (A.at(i) % k > A.at(i + 1) % k) {
					swap(A.at(i), A.at(i + 1));
				}
			}
			else if (i == N-1) {
				break;
			}
		}
	}

	for (i = 0; i < N; i++) {
		cout << A.at(i) << endl;
	}
	return 0;
}


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

int main(){
    string s;
    int ans=0;
    cin >> s;
    if(s=="SUN"){
        ans=7;
    }else if( s == "MON"){
        ans=6;
    }else if( s == "TUE"){
        ans=5;
    }else if( s == "WED"){
        ans=4;
    }else if( s ==  "THU"){
        ans=3;
    }else if( s ==  "FRI"){
        ans=2;
    }else if( s ==  "SAT"){
        ans=1;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
n,y=map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000+j*5000>y :
            break
        if i*10000+j*5000+(n-i-j)*1000==y :
            print( i,j,n-i-j )
            exit()
print("-1 -1 -1")


Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    ll N, P;
    cin >> N >> P;
    ll res = 2;
    ll ans = 1;
    while(P>=res*res) {
        int count = 0;
        if (P%res == 0) {
            while(P%res == 0) {
                P /= res;
                count++;
            }
            ans *= pow(res, count/N);
            res++;
        }
        else {
            res++;
        }
    }
    ans *= pow(P, 1/N);
    cout << ans << endl;
}

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

int power(int x, int y) ;
int gcd(int a, int b) ;

/*___________________________TEMPLATE END______________________________*/

signed main() {
    quickie
    int k ;
    string s ;
    cin >> k >> s ;
    if(SZ(s) > k) {
        rep(i, 0, k) {
            cout << s[i] ;
        }
        cout << "...\n" ;
    }
    else cout << s << "\n" ;
}

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

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

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int G[101][101];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int u,k,v;
cin>>u>>k;
for(int j=0;j<k;j++){
cin>>v;
G[u][v]=1;
}
}
for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
	cout<<G[i][j];
	(j==n)?cout<<endl:cout<<" ";
	}
}
return 0;
}

Measured memory_bytes: 1200
#include <cstdio>

int main(){
	int c,sum=0,p[6]={1,5,10,50,100,500};
	for(int i = 0; i < 6; i++){
		scanf("%d",&c);
		sum += c*p[i];
	}
	printf("%d\n", sum >= 1000 ? 1 : 0);

	return 0;
}

Measured memory_bytes: 2760
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

void solve(long long A, long long B, long long Q, std::vector<long long> s, std::vector<long long> t, std::vector<long long> x){
    REP(q, Q){
        ll xnow = x[q];
        vll tmp_s, tmp_t;
        auto it = lower_bound(ALL(s), xnow);
        if(it != s.end()){
            tmp_s.push_back(*it);
        }
        it = upper_bound(ALL(s), xnow);
        if(it != s.begin()){
            tmp_s.push_back(*(--it));
        }
        it = lower_bound(ALL(t), xnow);
        if(it != t.end()){
            tmp_t.push_back(*it);
        }
        it = upper_bound(ALL(t), xnow);
        if(it != t.begin()){
            tmp_t.push_back(*(--it));
        }

        ll ans = INF;
        for(auto ts: tmp_s){
            for(auto tt: tmp_t){
                ans = min(ans, abs(xnow-ts)+abs(ts-tt));
                ans = min(ans, abs(xnow-tt)+abs(ts-tt));
            }
        }
        cout<<ans<<endl;
    }
    
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> s(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&s[i]);
    }
    std::vector<long long> t(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&t[i]);
    }
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&x[i]);
    }
    solve(A, B, Q, std::move(s), std::move(t), std::move(x));
    return 0;
}


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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cin.tie(NULL);
    
    int n;
    cin >> n;
    
    while(n--)
        cout << "ACL";

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main(){
	long long int a, b;
	cin >> a >> b;
	if (a % 2 != b % 2) {
		cout << "IMPOSSIBLE" << endl;
	}
	else
		cout << (a + b) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.algorithm;

void main() {
	uint n = readln.chomp.to!uint;
	uint[] result;
	foreach (i; 0..n) {
		uint outNum = 0;
		bool[3] fieldPlayer;
		uint point = 0;
		while (outNum < 3) {
			auto str = readln.chomp;
			if (str == "HIT") {
					if (fieldPlayer[2]) point++;
					fieldPlayer[2] = fieldPlayer[1];
					fieldPlayer[1] = fieldPlayer[0];
					fieldPlayer[0] = true;
			} else if (str == "OUT") {
					outNum++;
			} else if (str == "HOMERUN"){
					foreach (j; 0..3) {
						if (fieldPlayer[j]) point++;
						fieldPlayer[j] = false;
					}
					point++;
			}
		}
		result ~= point;
	}
	foreach (r; result) r.writeln;
}

Measured memory_bytes: 2444
#include <algorithm>
#include <cstdio>

static const size_t n_max = 100;
static int dp[n_max+1][n_max+1];

int main() {
  size_t n;
  scanf("%zu\n", &n);
  for (size_t j = 1; j <= n; j++)
    for (size_t i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      dp[j][i] = a + dp[j][i-1] + dp[j-1][i] - dp[j-1][i-1];
    }
  int r = dp[1][1];
  for (size_t j = 1; j <= n; j++)
    for (size_t i = 1; i <= n; i++)
      for (size_t l = 0; l < j; l++)
        for (size_t k = 0; k < i; k++)
          r = std::max(r, dp[j][i] + dp[l][k] - dp[j][k] - dp[l][i]);
  printf("%d\n", r);
  return 0;
}

Measured memory_bytes: 2748
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def display(x, y):
    sx = chr(ord('A') + x)
    sy = str(y + 1)
    print("{}{}".format(sx, sy))

def main():
    H, W = map(int, input().split())

    for y in range(H):
        row = input().split()
        for x in range(W):
            if row[x] == "snuke":
                display(x, y)
                return

if __name__ == "__main__": main()


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<long long> pre(n + 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		pre[i + 1] = (pre[i] + a[i] - 1) % k;
	}
	map<int, int> mp;
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i >= k) mp[pre[i - k]]--;
		ans += mp[pre[i]];
		mp[pre[i]]++;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 12032
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n, m;
  cin >> n >> m;
  ll a[1010], b[1010];
  bitset<12> bs[1010];
  ll c[1010];
  rep(i, m)
  {
    cin >> a[i] >> b[i];
    rep(j, b[i])
    {
      int ci;
      cin >> ci;
      ci--;
      bs[i][ci] = 1;
    }
    c[i] = bs[i].to_ulong();
  }

  ll dp[1010][1 << 12];
  rep(i, 1010) rep(j, 1 << 12) dp[i][j] = INF;
  dp[0][0] = 0;

  rep(i, m) rep(j, 1 << n)
  {
    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
  }

  cout << (dp[m][(1 << n) - 1] == INF ? -1 : dp[m][(1 << n) - 1]) << endl;
  return 0;
}


Measured memory_bytes: 32640
import sys
sys.setrecursionlimit(10000000)
n,k=map(int,input().split())
CONST=10**9+7
path={i:list() for i in range(n)}
for i in range(n-1):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
used=[0]*n
used[0]=1
  
def bfs(pos, parent):
  res=k-parent
  if parent>0:
    deg=2
  else:
    deg=1
  for nex in path[pos]:
    if used[nex]:
      continue
    used[nex]=1
    res *= bfs(nex,deg)
    res = res%CONST
    deg += 1
  return res%CONST
    
print(bfs(0, 0))


Measured memory_bytes: 100564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n,ans=0;
    cin >> n;
    int l[n];
    rep(i,n) cin >> l[i];
    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j]) continue;
                if(l[j]==l[k]) continue;
                if(l[k]==l[i]) continue;
                int cnt = l[i]+l[j]+l[k];
                int mx = max({l[i],l[j],l[k]});
                if(mx<cnt-mx) ans++;
            }
        }
    }
    cout << ans << endl;
}


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

int main()
{
  int i;
  int N;
  int X;
  int L[N] = {};

  cin >> N >> X;
  for(i=0;i<N;i++){
    cin >> L[i];
  }

  int D = 0;
  i = 0;
  while (i<N+1 && D<=X){
    D += L[i];
    i++;
  }

  cout << i << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        int x = 0;
        long sum = 0;
        ArrayList<Integer> num = new ArrayList<>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        for(int i = 0; i < 2; i++) {
            if(i == 0){
                String[] line = br.readLine().split(" ");
                x = Integer.parseInt(line[0]);
            }
             
            else{
                String[] line = br.readLine().split(" ");
                for(int a = 0; a < x; a++){
                    sum = sum + Integer.parseInt(line[a]);
                    num.add(Integer.parseInt(line[a]));
                }
            }
             
        }
         
        System.out.println(Collections.min(num) +" "+ Collections.max(num) +" "+ sum);
         
 
         
    }
 
}

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

using namespace std;

int n;
int a[200010];

int main(){
    scanf("%d", &n);

    for(int i = 0; i < n; i++) scanf("%d", &a[i]);

    int mx = 0;

    for(int i = 0; i < n; i++){
        if(a[i] == mx + 1) mx++;
    }

    if(mx == 0) mx = n + 1;
    
    printf("%d\n", n - mx);
    
    return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <cctype>
#include <iostream>
using namespace std;
typedef string::const_iterator State;
class ParseError{};

int number(State&);
int term(State&);
int expression(State&);
int factor(State&);

int number(State& begin){
  int ret = 0;
  while(isdigit(*begin)){
    ret*=10;
    ret+=*begin-'0';
    ++begin;
  }
  return ret;
}

int term(State& begin){
  int ret = factor(begin);
  for(;;){
    if(*begin == '*'){
      ++begin;
      ret*=factor(begin);
    }
    else if(*begin == '/'){
      ++begin;
      ret/=factor(begin);
    }
    else{
      break;
    }
  }
  return ret;
}


int factor(State& begin){
  int ret;
  if(*begin == '('){
    ++begin;
    ret = expression(begin);
    ++begin;
  }
  else ret = number(begin);
  return ret;
}

int expression(State& begin){
  int ret = term(begin);
  for(;;){
    if(*begin == '+'){
      ++begin;
      ret+=term(begin);
    }
    else if(*begin == '-'){
      ++begin;
      ret-=term(begin);
    }
    else{
      break;
    }
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    State b = s.begin();
    int ans = expression(b);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    int[] b = new int[N+1];
    int[] c = new int[N+1];
    for(int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    int[][] dp = new int[N+1][3];
    for(int i = 1; i <= N; i++) {
      dp[i][0] = Math.max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
      dp[i][1] = Math.max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
      dp[i][2] = Math.max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
    }
    System.out.println(Math.max(dp[N][0], Math.max(dp[N][1], dp[N][2])));
  }
}


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


int main(){
    long X, cnt, t;
    cin >> X;
    t = 100;
    cnt = 0;
    while(t < X){
        t = t * 1.01;
        cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int k,n,i,m,d=0;
    cin>>k>>n;
    vector <int> a(n);
    for(i=0;i<n;++i)
        cin>>a[i];
    sort(a.begin(),a.end());
    m=d=a[n-1]-a[0];
    for(i=1;i<n;++i)
    {
        d=(a[n-1]-a[i])+(k-a[n-1])+a[i-1];
        m=min(d,m);
    }
    cout<<m;
    return 0;
}

Measured memory_bytes: 1024
import sys

Q = int(sys.stdin.readline().strip())
LR = []
for i in range(Q):
    LR.append([int(x) for x in sys.stdin.readline().strip().split()])

N = 10**5+1
Primes = list(range(N+1))
Primes[1] = 0

for p in Primes:
    if p * p > N+1: break
    if p == 0: continue
    for i in range(p + p, N+1, p):
        Primes[i] = 0

primes = [p for p in Primes if p > 0]

likes = []
r = 0
for n in range(N):
    if n%2 == 1 and Primes[n] > 0 and Primes[n//2+1] > 0:
        r += 1
    likes.append(r)

for i in range(Q):
    print(likes[LR[i][1]] - likes[LR[i][0]-1])


Measured memory_bytes: 26800
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] nums = new int[]{1,2,2,2};
      for(int i = 3; i>=0; i--) {
          nums[i] = n % 10;
          n /= 10;
      }
      
      for(int i = 0; i < (1 << 3); i++) { // 0: -, 1: +
          int res = nums[0];
          for(int j = 1; j < nums.length; j++) {
              if(((i >> (j-1)) & 1) == 0)
                res -= nums[j];
              else
                res += nums[j];
          }
          if(res == 7) {
            StringBuilder sb = new StringBuilder();
            sb.append((char)(nums[0]+'0'));
            for(int j = 1; j < nums.length; j++) {
              if(((i >> (j-1)) & 1) == 0)
                sb.append('-');
              else
                sb.append('+');
              sb.append((char)(nums[j]+'0'));
            }
            
            System.out.println(sb.toString() + "=7");
            return;
          }
      }

  }
}



Measured memory_bytes: 21332
n = int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
    if a[i+1]==a[i]+1:
        ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
signed main(){
    string s;
    bool f = true;
    int n , a , b;
    cin>>s;
    n = s.size();
    
    for(int i=0;i<n;i++){  
        if(s[i] != s[n-1-i]){
            f = false;
        }
    }
    
    a = 0 , b = (n-1)/2-1;
    while(a < b){
        if(s[a] != s[b]){
            f = false;
        }
        a++ , b--;
    }
    
    a = (n+3)/2-1 , b = n-1;
    while(a < b){
        if(s[a] != s[b]){
            f = false;
        }
        a++ , b--;
    }
    
    if(f == true){
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }

    return(0);
}


Measured memory_bytes: 256
import sys

N = int(input())
List = [[-1] * N for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        List[i][x - 1] = y

Max = 0

for i in range(2 ** N):

    flag = True
    Sum = 0
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            for k in range(N):
                if (List[j][k] != int((i >> k) & 1)) and List[j][k] != -1:
                    flag = False
            Sum += 1

    if flag:
        #print(i,Sum)
        Max = max(Max, Sum)

print(Max)


Measured memory_bytes: 73868
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<ll>p(A),q(B),r(C),s(X+Y+C);
  REP(i,A)cin>>p[i];
  REP(i,B)cin>>q[i];
  REP(i,C)cin>>r[i];
  sort(rALL(p));
  sort(rALL(q));
  sort(rALL(r));
  REP(i,X)s[i]=p[i];
  REP(i,Y)s[i+X]=q[i];
  REP(i,C)s[i+X+Y]=r[i];
  sort(rALL(s));
  cout<<accumulate(s.begin(),s.begin()+X+Y,0ll)<<endl;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#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
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;

ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll facto[200005];
void f()
{
	facto[0]=1;
	REP(i,1,200005)
	{
		facto[i]=mod((i*facto[i-1]),num);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll h,w;
    cin>>h>>w;
    if(h==1 || w==1)
    {
        cout<<"1\n";
    }
    else
    {
        cout<<(h*w+1)/2;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
  if(A>=K) cout << K;
  else if((A+B) >= K) cout << A;
  else cout << A - (K-A-B);
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define REP(i, n) for(int i=0; i<(n); i++)
#define REP2(i, x, n) for(int i=x; i<(n); i++)
#define SORT(n) sort((n).begin(), (n).end())
#define SORT2(n) sort((n).begin(), (n).end(), greater<int>())
using namespace std;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s;
    
    REP(i,n){
        
        cin >> s;
        
        string ma = s, mi = s;
        
        SORT2(ma);
        SORT(mi);
        
        int res1 = numeric_limits<int>::min();
        int res2 = numeric_limits<int>::max();
        
        res1 = max(res1, stoi(ma));
        res2 = min(res2, stoi(mi));
        
        cout << res1 - res2 << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i<n; i++)
    cin >> a.at(i);
  
  int answer = 0;
  
  while(true){
    bool check = false;
    for(int i = 0; i<n; i++){
      if(a.at(i) % 2 != 0)
        check = true;
    }
    if(check)
      break;
    
    for(int i = 0; i<n; i++)
      a.at(i) /= 2;
    
    answer++;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import math
a, b = map(int, input().split())

if ((a+1)/0.08).is_integer():
  s = [math.ceil(a/0.08), int((a+1)/0.08-1)]
else:
  s = [math.ceil(a/0.08), math.floor((a+1)/0.08-1)]
  
t = [int(b/0.1), int((b+1)/0.1 - 1)]

s_set = set([i for i in range(s[0], s[1]+1)])
t_set = set([i for i in range(t[0], t[1]+1)])

ans = list(s_set & t_set)
if ans:
  print(min(ans))
else:
  print(-1)
  

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S, T;
    cin >> S >> T;
    int size = T.size();
    vector<int> a;
    
    for (auto &i : S) { a.emplace_back(0); }
    bool f = false;
    for (int i=0; i<S.size(); ++i) {
        for (int j=0; j<i+1; ++j) {
            if ((S[i] == T[a[j]] || S[i] == '?') && a[j] > -1) {
                if (a[j] < size) {
                    a[j] += 1;
                    if (a[j] == size) { f = true;}
                }
            } else {
                if (a[j] < size) {
                    a[j] = -1;
                }
            }
        }
    }
    
    
    if (f) {
        vector<string> v;
        for (int j=0; j < S.size(); ++j) {
            if (a[j] < size) { continue; }
            string t = "";
            for (int i=0; i < S.size(); ++i) {
                if (i >= j && i - j < size) {
                    t += T[i - j];
                } else {
                    if (S[i] == '?') {
                        t += "a";
                    } else {
                        t += S[i];
                    }
                }
            }
            v.emplace_back(t);
        }
        sort(v.begin(), v.end());
        cout << v[0] << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256