akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
  
using namespace std;
  
char d[10][6];

void solve(int y,int x,int way){
  if(y==0&&x==0&&way==3){
  	cout<<"L";
  	return;
  }
  if(y==1&&x==0&&way==2){
  	cout<<"U";
  	return;
  }
  if(way==1){
    cout<<"R";
    if(y>0&&d[y-1][x+1]=='1')solve(y-1,x+1,2);
    else if(x<5&&d[y][x+1]=='1')solve(y,x+1,1);
    else if(y<8&&d[y+1][x+1]=='1')solve(y+1,x+1,4);
    else if(x>0&&d[y][x]=='1')solve(y,x,3);
  }
  else if(way==2){
    cout<<"U";
    if(x>0&&d[y-1][x-1]=='1')solve(y-1,x-1,3);
    else if(y>1&&d[y-2][x]=='1')solve(y-2,x,2);
    else if(x<4&&d[y-1][x]=='1')solve(y-1,x,1);
    else if(y<7&&d[y][x]=='1')solve(y,x,4);
  }
  else if(way==3){
    cout<<"L";
    if(y<8&&d[y+1][x]=='1')solve(y+1,x,4);
    else if(x>0&&d[y][x-1]=='1')solve(y,x-1,3);
    else if(y>0&&d[y-1][x]=='1')solve(y-1,x,2);
    else if(x<4&&d[y][x]=='1')solve(y,x,1);
  }
  else if(way==4){
    cout<<"D";
    if(x<4&&d[y+1][x]=='1')solve(y+1,x,1);
    else if(y<7&&d[y+2][x]=='1')solve(y+2,x,4);
    else if(x>0&&d[y+1][x-1]=='1')solve(y+1,x-1,3);
    else if(y>1&&d[y][x]=='1')solve(y,x,2);
  }
  return;
}
  
int main(void){
  for(int i=0;i<9;i++){
    cin>>d[i];
  }
  solve(0,0,1);
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1132
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};




int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  vvl G(n);
  rep(i,n-1){
    ll a,b;cin>>a>>b;
    a--;b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  vl c(n);
  rep(i,n)cin>>c[i];
  sort(c.begin(),c.end());
  ll ans=0;
  rep(i,n-1)ans+=c[i];
  cout<<ans<<endl;
  reverse(c.begin(),c.end());
  queue<ll>q;
  vl used(n,false);
  q.push(0);
  vl res(n);
  rep(i,n){
    ll k=q.front();
    q.pop();
    res[k]=c[i];
    used[k]=true;
    for(auto x:G[k]){
      if(used[x])continue;
      q.push(x);
    }
  }
  rep(i,n){
    cout<<res[i];
    if(i!=n-1)cout<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e3 + 5;
	long mod = (long) 1e9 + 7;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		double prob[] = new double[N + 1];
		for (int i = 1; i <= N; i++) {
			prob[i] = in.nextDouble();
		}
		double dp[] = new double[N + 1];// ;
		dp[0] = 1;
		for (int i = 1; i <= N; i++) {
			for (int j = i; j >= 0; j--) {
				dp[j] = (j == 0 ? 0 : dp[j - 1] * prob[i]) + (dp[j]) * (1 - prob[i]);
			}
		}
		double ans = 0.0;
		for (int i = N / 2 + 1; i <= N; i++) {
			ans += dp[i];
		}
		pw.printf("%.09f", ans);

	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

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

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n, d; cin >> n >> d;
  vector<vi32> x(n, vi32(d));
  auto check = [](int x) {
    for (int i = 1; ; i++) {
      if (i * i == x) return true;
      if (i * i > x) return false;
    }
  };
  rep(i, n) cin >> x[i];
  int ans = 0;
  rep(i, n) repi(j, i + 1, n) {
    int sum = 0;
    rep(k, d) sum += power(x[i][k] - x[j][k], 2);
    if (check(sum)) ans++;
  }
  cout << ans << '\n';
}


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

class state{
public:
    int a,b;
    state(int a=0, int b=0):a(a),b(b){}
    bool operator < (const state &s) const {
        if(a == s.a) return b > s.b;
        return a < s.a;
    }
};

state v[100];

int main(){
    int n,m;
    while(cin >> n >> m){
        int ans = 0;
        bool f = false;
        for(int i=0;i<m;i++) cin >> v[i].a >> v[i].b;
        sort(v,v+m);

        if(v[0].a == 1){
            for(int i=0;i<m;i++){
                if(v[i].b == n){
                    ans++;
                    f = true;
                    break;
                }
                int maxb = -1, maxi = -1;
                for(int j=m-1;j>i;j--){
                    if(maxb < v[j].b && v[j].a <= v[i].b + 1){
                        maxb = v[j].b;
                        maxi = j;
                    }
                }
                ans++;
                i = maxi - 1;
                if(maxi == -1){
                    break;
                }
            }
        }

        if(!f) cout << "Impossible" << endl;
        else cout << ans << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[10],b[10];
  for(int i=0;i<10;i++)cin>>a[i];
  for(int i=0;i<10;i++)cin>>b[i];
  sort(a,a+10);
  sort(b,b+10);
  cout<<a[9]+a[8]+a[7]<<" "<<b[9]+b[8]+b[7]<<endl;
  return 0;
}

Measured memory_bytes: 1180
s=input()
n=int(input())
q=[list(map(str,input().split())) for i in range(n)]
atama=0
x=0
for i in range(n):
  if q[i][0]=='2':
    x+=1

oshiri=len(s)+x-1
ans=[]
for i in range(len(s)+x):
    ans.append('x')
x=0
for i in range(n)[::-1]:
  if q[i][0]=='1':
    x+=1
  else:
    if (int(q[i][1])+x)%2==0:
      ans[oshiri]=q[i][2]
      oshiri-=1
    else:
      ans[atama]=q[i][2]
      atama+=1

if x%2==1:
  s=s[::-1]

for i in range(len(s)):
  ans[i+atama]=s[i]

answer=ans[0]
for i in range(1,len(ans)):
    answer+=ans[i]
    
print(answer)

Measured memory_bytes: 42544
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll H, W, X;
vector<vector<int>> c(4, vector<int>(4));

//解法
void solve() {

	if (c[2][2] == c[2][1] + c[1][2] - c[1][1]
		&& c[2][3] == c[2][1] + c[1][3] - c[1][1]
		&& c[3][2] == c[3][1] + c[1][2] - c[1][1]
		&& c[3][3] == c[3][1] + c[1][3] - c[1][1]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return;
}

int main() {
	//入力
	rep(i, 3) rep(j, 3) {
		cin >> c[j+1][i+1];
	}
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,x,t;
  cin >> n >> x >> t;
  int ans = t *dup(n,x);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
import sys
from itertools import accumulate
n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
aa = list(accumulate(a))
MOD = 10**9+7
ans = 0
for i in range(n):
    ans += a[i]*(aa[n-1] - aa[i]) % MOD
    ans %= MOD
print(ans)


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  
  int total=0;
  
  if(C<=A+B){
    total=B+C;
  }else{
    total=A+2*B+1;
  }
  
  cout << total << endl;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
using namespace std;
char str[MAXN+5],ans[MAXN+5];
char inv[200];
int N,K,seq[MAXN+5];
int main()
{
	inv['A']='B',inv['B']='A';
	scanf("%d %d",&N,&K);
	scanf("%s",str+1);
	for(int i=1;i<=N;i++)
		seq[i]=str[i]-'A';
	int mv=0,turn=0;
	while(mv<N)
	{
		K--;
		if((seq[mv+1]^turn)==0)
		{
			seq[mv+1]^=1;
		}
		else
		{
			mv++;
			turn^=1;
		}
		if(K==0)
			break;
	}
	int len=0;
	for(int i=mv+1;i<=N;i++)
	{
		if(seq[i]^turn)
			ans[++len]='B';
		else
			ans[++len]='A';
	}
	if(K==0||N%2==0)
	{
		for(int i=1;i<=mv;i++)
			if((i%2)^(turn))
				ans[++len]='B';
			else
				ans[++len]='A';
		printf("%s\n",ans+1);
		return 0;
	}
	for(int i=1;i<=N;i++)
		if(i%2)
			ans[++len]='A';
		else
			ans[++len]='B';
	if(K%2==1)
		ans[1]='B';
	printf("%s\n",ans+1);
	return 0;
}
/*
5 15
ABABA

*/

Measured memory_bytes: 1536
# coding: utf-8
import re

n = int(input())
s = input()

R = set([m.start() for m in re.finditer('R', s)])
G = set([m.start() for m in re.finditer('G', s)])
B = set([m.start() for m in re.finditer('B', s)])
#print(R,G,B)
x=0
li=[]
for r in R:
    for g in G:
        
        if r < g:
            gr = g-r
            li.extend([r-gr in B, g+gr in B, (gr%2 == 0 and r+gr//2 in B)])
        
        else:
            rg = r-g
            li.extend([g-rg in B, r+rg in B, (rg%2 == 0 and g+rg//2 in B)])

print(len(R)*len(G)*len(B)-sum(li))

Measured memory_bytes: 52828
#include<bits/stdc++.h>
using namespace std;
struct Node
{
	int data;
	Node *next;
};
struct Queue
{
	Node *head;
	Node *la;
	Queue()
	{
		head=(Node *)malloc(sizeof (Node));
		la=(Node *)malloc(sizeof (Node));
		head =NULL;
	}
	bool empty()
	{
		if(head==NULL) return 1;
		else return 0;
	}
	void push(int x)
	{
		Node *p1;
		p1=(Node *)malloc(sizeof (Node));
		p1->data=x;
		if(head==NULL) 
		{
			head=p1;
			la=p1;
		}
		else
		{
			la->next=p1;
			la=p1;
		}
		la->next=NULL;
	}
	void pop()
	{
		Node *p1;
		p1=head->next;
		delete head;
		head=p1;
	}
	int front()
	{
		return head->data;
	}
	void clear()
	{
		while(head!=NULL) head=head->next;
	}
}; 
vector<pair<int,int> > nei[1000005],cit[1000005];
vector<int>comp;
int vis[1000005];
vector<int>newnei[1000005];
int dp[1000005];
int par[1000005];
void init(int x)
{
	par[x]=x;
}
int find(int x)
{
	return (par[x]==x)?x:par[x]=find(par[x]);
}
void merge(int x,int y)
{
	x=find(x);y=find(y);
	par[x]=y;
}
queue<int> q;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y,c;
		scanf("%d %d %d",&x,&y,&c);
		x--,y--,c--;
		cit[c].push_back(make_pair(x,y));
		comp.push_back(c);
	}
	sort(comp.begin(),comp.end());
	comp.erase(unique(comp.begin(),comp.end()),comp.end());
	int newci=n;
	for(int i=0;i<comp.size();i++)
	{
		int cmp=comp[i];
		for(int j=0;j<cit[cmp].size();j++)
		{
			int v=cit[cmp][j].first,u=cit[cmp][j].second;
			init(v);init(u);
			vis[v]=vis[u]=0;
		}
		for(int j=0;j<cit[cmp].size();j++)
		{
			merge(cit[cmp][j].first,cit[cmp][j].second);
		}
		for(int j=0;j<cit[cmp].size();j++)
		{
			int v=cit[cmp][j].first;
			v=find(v);
			if(!vis[v])
			{
				vis[v]=newci;
				newnei[v].push_back(newci);
				newnei[newci].push_back(v);
				newci++;
			}
			if(!vis[cit[cmp][j].first])
			{
				int u=cit[cmp][j].first;
				newnei[vis[v]].push_back(u);
				newnei[u].push_back(vis[v]);
				vis[cit[cmp][j].first]=newci;
			}
			if(!vis[cit[cmp][j].second])
			{
				int u=cit[cmp][j].second;
				newnei[vis[v]].push_back(u);
				newnei[u].push_back(vis[v]);
				vis[cit[cmp][j].second]=newci;
			}
		}
	}
	for(int i=0;i<newci;i++) dp[i]=-2;
	dp[0]=1;
	q.push(0);
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		for(int k=0;k<newnei[v].size();k++)
		{
			int u=newnei[v][k];
			if(dp[u]==-2)
			{
				dp[u]=dp[v]+1;q.push(u);
			}
		}
	}
	cout<<dp[n-1]/2;
}

Measured memory_bytes: 95348
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  string S,T; cin>>S>>T;
  ll ans=0;
  rep(i,S.size())
  {
    if(S.at(i)!=T.at(i))
    {
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
	string s;
	getline(cin, s);

	for(int i=0; i<s.length(); i++)
	{
		if((int)s[i]>=65 && (int)s[i]<=91)
		{
			s[i] = s[i]-'A' + 'a' ;
		}
		else if((int)s[i]>=97 && (int)s[i]<=122)
		{
            s[i] = s[i] - 'a'  +  'A' ;
		}
	}
	cout <<s <<'\n';
	return 0;
}


Measured memory_bytes: 3208
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a > 10) {
          System.out.println(b);
        } else {
          System.out.println(b + (100 * (10 - a)));
        }
    }
}

Measured memory_bytes: 20564
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

ans=1
for i in T:
    ans = lcm(ans,i)

print(ans)


Measured memory_bytes: 3060
s = input()

ite = 0
if len(s) % 2 == 0:
    ite = int(len(s) / 2)
else:
    ite = int((len(s) - 1) / 2)

count = 0
for i in range(ite):
    if s[i] == s[-i - 1]:
        continue
    count += 1

print(count)

Measured memory_bytes: 3060
#include<stdio.h>

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

Measured memory_bytes: 600
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
	int b;
	string a;
	cin>>a;
	b=a.size();
	for(int i=b-1;i>=0;i--)
	{
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3148
function Main(input){
    input=input.split("\n");
     
    var vals = input[0].split(' ');
     
    var val1 = parseInt(vals[0]);
    var val2 = parseInt(vals[1]);
     
    var ans1 = val1 * val2;
    var ans2 = 2 * (val1 + val2);
     
    console.log("%d %d", ans1, ans2);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15096
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	long long int a, b, c = 1;
	cin >> a >> b;
	if (a % b == 0)
		cout << -1 << endl;
	else {
		while ((c * a) % b == 0) {
			c++;
		}
		cout << c * a << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 998244353;

Int f(Int x) {
    Int cnt = 0;
    while (x > 0) {
        x /= 10;
        cnt++;
    }
    return cnt;
}

int main() {
    Int n;
    cin >> n;
    Int res = 0;
    for (Int i = 1; i <= n; i++) {
        if (f(i) % 2 == 1) res++;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())
lis = [0 for i in range(N)]

i = 0
p = 1
ans = max(N-K +1,0)
while K:
  p/=2
  last = K
  K = math.ceil(K/2)
  cnt = max(min(last,N+1)- K , 0)
  ans += cnt * p
  if K ==1:
    break
    
print(ans/N)

Measured memory_bytes: 3864
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

ll N;
vector<ll> isVisited;
vector<vector<ll>> edge;

ll nodeid(ll x, ll y) { return min(x,y)*N+max(x,y); }

void visit(ll m) {
  if(isVisited[m]==-1) throw m;
  if(isVisited[m]>0) return;

  isVisited[m] = -1;
  ll layer=0;
  for(ll j=0; j<edge[m].size(); ++j){
    visit(edge[m][j]);
    layer = max(layer, isVisited[edge[m][j]]);
  }
  isVisited[m]=layer+1;
}

int main(){
  cin >> N;
  isVisited.resize(N*N, 0);
  edge.resize(N*N);
  
  for(ll i=0; i<N; ++i) {
    ll from, to;
    cin >> from;
    for(ll j=0; j<N-2; ++j) {
      cin >> to;
      edge[nodeid(i,from-1)].push_back(nodeid(i,to-1));
      from = to;
    }
  }
  
  try{
    for(ll i=0; i<edge.size(); ++i) {
      if(edge[i].size()==0) continue;
      if(isVisited[i]==0) { visit(i); }
    }

  ll ans = 0;    
    for(ll i=0; i<edge.size(); ++i) {
      if(edge[i].size()==0) continue;
      ans = max(isVisited[i],ans);
    }
    cout << ans << endl;
    
  }catch(ll& e){
    cout << -1 << endl;
  }

  return 0;
}


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

int main()
{
  string s;
  cin >> s;
  string ans;
  switch (s[0]) {
  case 'S':
    ans = "Cloudy";
    break;
  case 'C':
    ans = "Rainy";
    break;
  case 'R':
    ans = "Sunny";
    break;
  default:
    ans = "";
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  int n;
  ci >> n;

  int a[100001];
  rep(i, n) ci >> a[i];

  int sum = 0;
  bool pm = true;
  rep(i, n) {
    if(pm && sum + a[i] > 0 || !pm && sum + a[i] < 0) {
      sum += a[i];
    } else if(sum + a[i] == 0) {
      if(pm) sum = 1;
      else   sum = -1;
      cnt++;
    } else {
      if(pm) {
	cnt += abs(sum + a[i]) + 1;
	sum = 1;
      } else {
	cnt += abs(sum + a[i]) + 1;
	sum = -1;
      }
    }
    pm = !pm;
  }

  sum = 0;
  pm = false;
  rep(i, n) {
    if(pm && sum + a[i] > 0 || !pm && sum + a[i] < 0) {
      sum += a[i];
    } else if(sum + a[i] == 0) {
      if(pm) sum = 1;
      else   sum = -1;
      cntt++;
    } else {
      if(pm) {
	cntt += abs(sum + a[i]) + 1;
	sum = 1;
      } else {
	cntt += abs(sum + a[i]) + 1;
	sum = -1;
      }
    }
    pm = !pm;
  }

  co << min(cnt, cntt) << en;
  
  return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range(n):
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=[]
for i in range(n):
    d.append(list(map(int, input().split())))
#print(d)

now=d[0][0]
for i in range(n-2):
    if d[i][1]==d[i][0] and d[i+1][1]==d[1+i][0] and d[i+2][1]==d[2+i][0]:
        print("Yes")
        sys.exit()
print("No")

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

using namespace std;

int main(){
        int a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a, a+3);
        if(a[0]==5&&a[1]==5&&a[2]==7){
                cout<<"YES"<<endl;
        }
        else{
                cout<<"NO"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1400
#define INF 0x3fffffff
using namespace std;

int n,m,ans=0;
int d[MAXN+5][MAXN+5];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&d[i][j]);
            d[i][j]=!d[i][j];
            ans=max(ans,d[i][j]);
        }
    for(int i=2;i<=n;i++)
        for(int j=2;j<=m;j++)
            if(d[i][j])
            {
                d[i][j]=min(d[i-1][j],min(d[i][j-1],d[i-1][j-1]))+1;
                ans=max(ans,d[i][j]);
            }
    /*for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            printf("%d  ",d[i][j]);
        printf("\n");
    }*/
    printf("%d\n",ans*ans);
}



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

int main(){
  int n, m, x, y;
  cin >> n >> m >> x >> y;

  vector<int> vecx(n+1);
  for(int i=0;i<n;i++){
    cin >> vecx.at(i);
  }
  
  vector<int> vecy(m+1);
  for(int i=0;i<m;i++){
    cin >> vecy.at(i);
  }
  
  vecx.at(n) = x;
  vecy.at(m) = y;
  
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  int xmax =vecx.at(n);
  int ymin = vecy.at(0);

  if(xmax < ymin){
  cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
   
}
    

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

int main(){
    int N;
    cin >> N;
    int a = N % 10;
    int b = (N - a)/10%10;
    int c = (N - a - 10*b)/100;
    int answer;
    if(c < b || (c == b)&(b < a)){
        answer = 111*(c+1);
    }
    else{
        answer = 111*c;
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted
/****************************/
#include<bits/stdc++.h>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define itn int
#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

/***************************/
ll t[100010],d[100010];
/***************************/
int main(void){
	ll n,k;cin >> n>>k;
	vpi a(n);
	for(int i = 0;i < n;i++){
		cin >> t[i] >> d[i];
		a[i] = mp(d[i],--t[i]);
	}
	sort(all(a)); reverse(all(a));
	//group S
	long long sum = 0LL;
	vector<vector<ll>> S(n,vector<ll>(0));
	vector<vector<ll>> T(n,vector<ll>(0));

	for(int i = 0;i < k;i++){
		sum += a[i].first;
		S[a[i].second].pb(a[i].first);
	}
	for(int i = k;i < n;i++){
		T[a[i].second].pb(a[i].first);
	}
	
	vector<ll> type(n);
	vector<ll> type2(n);
	for(int i = 0;i < n;i++){
		sort(all(S[i]));
		sort(all(T[i])); reverse(all(T[i]));
		type[i] = S[i].size();
		type2[i] = T[i].size();
	}
	
	ll x = 0LL;
	for(int i = 0;i < n;i++){
		if(type[i] >= 1) x++;
	}
	
	ll ans = sum + (x*x);
	
	priority_queue<ll> OUT;
	priority_queue<ll,vector<ll>,greater<ll>> IN;
	for(int i = 0;i < n;i++){
		if(type[i] >= 2){
			for(int j = 0;j < type[i] - 1;j++) IN.push(S[i][j]);
		}
		if(type[i] == 0 && type2[i] >= 1) OUT.push(T[i][0]);
	}
	//debug(IN.size());debug(OUT.size());
	while(!IN.empty() && !OUT.empty()){
		ll i,o;
		i = IN.top(); IN.pop();
		sum -= i;
		o = OUT.top(); OUT.pop();
		sum += o;
		x++;
		ans = max(ans,sum + (x*x));
	}
	cout << ans << endl;
	
}

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


int main() {
  int A, P;
  cin >> A >> P;
  
  int ans = (3*A + P) / 2;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int a, b, c, x, y, ans = 0;
	cin >> a >> b >> c >> x >> y;
	
	while(x > 0 || y > 0){
		if(x == 0){
			--y;
			if(2*c > b) ans += b;
			else ans += 2*c;
		}
		else if(y == 0){
			--x;
			if(2*c > a) ans += a;
			else ans += 2*c;
		}
		else{
			--x;
			--y;
			//cout << 2*c << " " << b +a << " " << ans <<endl;
			if(2*c > a+b) ans += b+a;
			else ans += 2*c;
			//cout << 2*c << " " << b +a << " " << ans <<endl;
		}
	}
	cout << ans;
			

}


Measured memory_bytes: 256
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1]:
    print 2*x[0] - 2
    continue

  if x[0]+1 == x[1]:
    print 2*x[0] - 2
    continue

  q = x[0]*x[1]
  q = int(math.sqrt(q))

  if q*q == x[0]*x[1]:
    q -= 1

  if q*(q+1) >= x[0]*x[1]:
    print 2*q - 2
    continue

  print 2*q - 1


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

int main(){
  int h,w;
  cin >> h >> w;
  
  vector <string> v1(h);

  for(int i = 0;i<h;i++){
    cin >> v1.at(i);
  }

  for (int i = 0 ; i < h+2; i++){
    if(i==0 || i==h+1) cout << string(w+2,'#')<< endl;
    else cout << '#' + v1.at(i-1) + '#' << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,l,c[100000];
int main() {
    cin>>m>>n;
    for (int i = 1; i*i <= n; ++i) {
        if(n%i==0) {
        	c[l++]=i;
        	if(i*i!=n) c[l++]=n/i;
		}
    }
    sort(c,c+l);
    for (int i = 0; i < l; ++i) {
        if(c[i]>=m) {
        	cout<<n/c[i]<<endl;
        	return 0;
		}
    }
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
//using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(all(a));
    ll mid;
    ll ans=0;
    vector<ll>b=a;
    vector<ll>c=a;
    if(n%2==1){
        mid=-1*b[n/2];
        rep(i,n){
            b[i]+=mid;
            ans+=abs(b[i]);
        }
        cout<<ans<<endl;
        return 0;
    }
    else{
        ll mid1=-1*c[n/2-1],mid2=-1*c[n/2];
        ll ans1=0,ans2=0;
        rep(i,n){
            c[i]+=mid1;
            ans1+=abs(c[i]);
        }
        c=a;
        rep(i,n){
            c[i]+=mid2;
            ans2+=abs(c[i]);
        }
        ans=min(ans1,ans2);
        cout<<ans<<endl;
    }

}











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

using namespace std;

int main() {
    int N;
    cin >> N;
    for(int i = 0; i < 100; i++) {
        int t = N - 4 * i;
        if (t >= 0 && t % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
int n,y,b,r,t,bm;
int i,j;
double gen,max,a;

	scanf("%d",&n);
	while(n!=0){
		gen=1.0;
		max=0.0;
		scanf("%d",&y);
		for(i=0;i<n;i++){
			scanf("%d %d %d",&b,&r,&t);
			if(t==1){
				gen=1.0+y*(r/100.0);
			}
			else if(t==2)	{
				gen=1.0+(r/100.0);
				a=gen;
				for(j=0;j<y-1;j++){
					gen*=a;
				}	
			}
			if(max<gen){
				bm=b;
				max=gen;
			}
		}
		printf("%d\n",bm);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;
bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}
int main()
{
    ll N;
    cin >> N;
    vector<P> vec(N);
    rep(i, N) {
        ll A, B;
        cin >> A >> B;
        vec[i] = make_pair(A, B);
    }
    sort(all(vec), pairCompareS);
    ll time = 0;
    rep(i, N) {
        time += vec[i].first;
        if (time > vec[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	string S;
	cin >> S;

	int N = S.size();

	string S1 = S.substr(0, (N - 1) / 2);
	string S2 = S.substr((N + 1) / 2, (N - 1) / 2);

	if (S1 == S2) {
		string T = S1;
		int M = T.size();
		if (1 == M % 2) {
			string T1 = S.substr(0, (M - 1) / 2);
			string T2 = S.substr((M + 1) / 2, (M - 1) / 2);
			reverse(T2.begin(), T2.end());
			if (T1 == T2) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			string T1 = S.substr(0, M/ 2);
			string T2 = S.substr(M/ 2, M/ 2);
			reverse(T2.begin(), T2.end());
			if (T1 == T2) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int M;

void mul(vvi &A, const vvi B) {
    vvi t(A.size(), vi(B[0].size(), 0));
    for (size_t i=0; i<A.size(); ++i)
        for (size_t j=0; j<B[0].size(); ++j)
            for (size_t k=0; k<A[0].size(); ++k)
                (t[i][j] += (A[i][k] * B[k][j]) % M) %= M;
    swap(A, t);
}

void pow(vvi &A, int k) {
    int n = A.size();
    vvi t(n, vi(n, 0));
    for (int i=0; i<n; ++i) t[i][i] = 1;
    while (k) {
        if (k & 1) mul(t, A);
        k >>= 1;
        mul(A, A);
    }
    swap(A, t);
}

int main() {
    int n, a, b, c, t;
    while (cin >> n >> M >> a >> b >> c >> t) {
        if ( ! n) break;
        vvi A(n, vi(n, 0));
        for (int i=0; i<n; ++i) cin >> A[0][i];

        vvi B(n, vi(n, 0));
        for (int i=0; i<n; ++i) {
            if (i+1 < n) B[i][i+1] = a;
            B[i][i] = b;
            if (0 <= i-1) B[i][i-1] = c;
        }
        pow(B, t);
        mul(A, B);
        for (int i=0; i<n; ++i) cout << (i==0 ? "" : " ") << A[0][i];
        cout << endl;
    }
}


Measured memory_bytes: 3188
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int h,w,n;
		cin>>h>>w>>n;
		ll int ans=(n+max(h,w)-1)/max(h,w);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=510;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,dis[N][N],val[N][N],dx[4]={1,0,0,-1},dy[4]={0,1,-1,0};
queue<pii> q;

bool in(int x,int y) {
	return 1<=x&&x<=n&&1<=y&&y<=n;
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) val[i][j]=1,dis[i][j]=min(i,min(j,min(n-i+1,n-j+1)));
	int ans=0;
	for(int i=1;i<=n*n;i++) {
		int id=gi(),x=(id-1)/n+1,y=(id-1)%n+1;
		ans+=dis[x][y];--dis[x][y];q.push(mp(x,y));
		val[x][y]=0;
		while(!q.empty()) {
			int x=q.front().fi,y=q.front().se;
			q.pop();
			for(int d=0;d<4;d++) {
				int xx=x+dx[d],yy=y+dy[d];
				if(!in(xx,yy)) continue;
				if(dis[xx][yy]>dis[x][y]+val[xx][yy]) dis[xx][yy]=dis[x][y]+val[xx][yy],q.push(mp(xx,yy));
			}
		}
	}
	cout<<ans-n*n;
	return 0;
}


Measured memory_bytes: 5556
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    x, y = list(map(int, input().rstrip('\n').split()))
    if (x + y) % 3 != 0 or x <= 0 or y <= 0:
        print(0)
    else:
        t = (x + y) // 3
        for i in range(t + 1):
            xn = i * 2 + (t - i)
            yn = i + (t - i) * 2
            if xn == x and yn == y:
                print(alg_combination_mod(i + t - i, i, mod))
                exit()
        print(0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38768
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u64>();
    let (a, b) = (line[0], line[1]);
    let diff = b - a;

    println!("{}", diff*(diff-1)/2 -a);

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

typedef struct Node {
    long id;
    vector<pair<long, ll> > connects;
} Node;

void solve(const vector<Node> &nodes, const long &k, map<long, ll> &table) {
    queue<pair<long, ll> > q;
    Node n = nodes[k];
    ll cost;

    long i, len = n.connects.size();

    for (i = 0; i < len; i++) {
        table[n.connects[i].first] = n.connects[i].second;

        q.push(make_pair(n.connects[i].first, n.connects[i].second));
    }

    table[k] = -1;

    while (!q.empty()) {
        n = nodes[q.front().first];
        cost = q.front().second;

        q.pop();

        len = n.connects.size();
        for (i = 0; i < len; i++) {
            if (table[n.connects[i].first] == 0) {
                table[n.connects[i].first] = n.connects[i].second + cost;

                q.push(make_pair(n.connects[i].first, n.connects[i].second + cost));
            }
        }
    }

    table[k] = 0;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    long n;

    cin >> n;

    vector<Node> nodes(n);
    long a, b;
    ll c;
    long q, k;

    long i, len = n - 1;

    for (i = 0; i < n; i++) nodes[i].id = i;

    for (i = 0; i < len; i++) {
        cin >> a >> b >> c;

        a--;
        b--;

        nodes[a].connects.push_back(make_pair(b, c));
        nodes[b].connects.push_back(make_pair(a, c));
    }

    cin >> q >> k;

    k--;

    map<long, ll> table;

    solve(nodes, k, table);

    for (i = 0; i < q; i++) {
        cin >> a >> b;

        a--;
        b--;

        cout << table[a] + table[b] << endl;
    }

    return 0;
}


Measured memory_bytes: 17520
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.size(),c=0;
	for(int i=0;i<n;i++)if(s[i]-48==i%2)c++;
	cout<<min(c,n-c)<<endl;
	return 0;
}

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

using namespace std;

/** whole range */
#define whole(xs) (xs).begin(), (xs).end()

namespace {
    typedef long long ll;
    const ll INF = 1LL<<54;
    const bool debug = false;
    /** output whole vector. ex) vector<int>{1, 2, 3} -> '1 2 3'. */
    template<typename T>
    ostream& operator<<(ostream& os, const vector<T>& xs) {
       if (xs.empty()) return os;
       os << xs[0];
       for (auto i = 1; i < xs.size(); i++) os << ' ' << xs[i];
       return os;
    }

    ll N, M, L;
    vector<ll> K, S;
    void input() {
        cin >> N >> M >> L;
        K.resize(N);
        S.resize(M);
        for (auto i = 0; i < N; i++) {
            cin >> K[i];
            K[i]--;
        }
        for (auto i = 0; i < M; i++) cin >> S[i];
    }

    void solve() {
        ll f[N + 1][N + 1]; {
            for (auto i = 0; i < N + 1; i++) {
                for (auto j = 0; j < N + 1; j++) {
                    f[i][j] = INF;
                }
            }
        }
        sort(whole(K));
        vector<ll> cumsum(M + 1, 0); {
            for (auto i = 0; i < M; i++) {
                cumsum[i + 1] = cumsum[i] + S[i];
            }
        }

        if (debug) {
            cout << "cumsum: " << cumsum << endl;
        }

        auto g = [&](ll a, ll b) {
            return (cumsum[K[b] + 1] - cumsum[K[a]]) / L;
        };
        f[1][0] = g(0, 1);
        for (auto k = 0; k < N - 2; k++) {
            for (auto p = 0; p < k; p++) {
                f[k + 1][p] = min(f[k + 1][p], f[k][p] + g(k, k + 1));
                f[k + 1][k] = min(f[k + 1][k], f[k][p] + g(p, k + 1));
            }
        }

        if (debug) {
            cout << endl;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    cout << f[i][j] << " ";
                }
                cout << endl;
            }
        }

        ll ans = INF;
        auto k = N - 2;
        for (auto p = 0; p < k; p++) {
            ans = min(ans, f[k][p] + g(k, N - 1) + g(p, N - 1));
            //cout << k << " " << p << " -> " << f[k][p] << "&" << g(k, N - 1) << "&" << g(p, N - 1) << endl;
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
}

Measured memory_bytes: 35632
S = input()

for i in range(1<<(4-1)+1):
    eq = S[0:1]
    for j in range(1,len(S)):
        if i & 1 << j:
            eq += '+' + S[j:j+1]
        else:
            eq += '-' + S[j:j+1]
    if eval(eq) == 7:
        print(eq+'=7')
        break


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

int main() {
    vector<string> s(3);
    cin >> s[0] >> s[1] >> s[2];
    vector<int> cnt(3, 0);
    int now = 0;
    while (1) {
        if (cnt[now] == s[now].size()) break;
        int next = s[now][cnt[now]] - 'a';
        cnt[now]++;
        now = next;
    }
    cout << (char)('A' + now) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int X = scan.nextInt();
    int Y = scan.nextInt();
    if (X > 9 | Y > 9){
      System.out.println(-1);
    } else{
      System.out.println(X * Y);
    }
  }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstring>

using namespace std;

string s;
int cnt1 = 0;
bool flag[26] = {false};
int cnt[26];
int pp;

int main()
{
	getline(cin,s);
	//int l = s.size();
	for(int i = 0;i <= 3;i ++){
		cnt[s[i]-'A']++;
		//cout <<cnt[s[i]-'A'] <<endl;
	}
	for(int i = 0;i <= 3;i ++){
		if(cnt[s[i]- 'A'] == 2&&!(flag[s[i]-'A']))
		{
			cnt1++;
			flag[s[i]-'A']=true;	
			//cout <<cnt1 <<endl;
		}
		
	}
	if(cnt1 == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
ll dp[100005][4];
int main(){
  string s;
  cin>>s;
  int n=s.size();
  dp[0][0]=1;
  for(int i=0;i<n;i++){
      for(int j=0;j<4;j++){
          if(s[i]=='?')dp[i+1][j]+=dp[i][j]*3;
          else dp[i+1][j]+=dp[i][j];
          dp[i+1][j]%=mod;
      }
      if(s[i]=='A'||s[i]=='?')dp[i+1][1]+=dp[i][0];
      if(s[i]=='B'||s[i]=='?')dp[i+1][2]+=dp[i][1];
      if(s[i]=='C'||s[i]=='?')dp[i+1][3]+=dp[i][2];
      for(int j=0;j<4;j++){
          dp[i+1][j]%=mod;
      }
  }
  cout<<dp[n][3]<<endl;
}

Measured memory_bytes: 3664
#include <stdio.h>

#define N 3
#define NN N*N
#define BACK 0
#define FOUND 1

int dfs(int *);
int visit(int *, int);
int heuristic(int *);
void printpuzzle(int *);
void puzzlecopy(int *, int *);
int zettaichi(int);


int d; //depthlimit
int goal[NN+1];

int main()
{
  int i, j, number;
  int g; // current depth
  int puzzle[NN+1]; //添字０はつかわないため＋１
  
  puzzle[0] = 0;
  for(i = 1; i <= NN; i++) {
    scanf("%d",&puzzle[i]);
  }

  d = heuristic(puzzle);
  
  goal[0] = 0;
  goal[NN] = 0;
   for(i = 1; i < NN; i++) {
     goal[i] = i;
  }


  dfs(puzzle);

  return 0;
}

int heuristic(int *puzzle)
{
  int i, j, x, tatecost, yokocost, totalcost = 0;

  for(i = 1; i <= NN; i++) {
    if(puzzle[i] != 0) {
      tatecost = zettaichi((i-1)/3 - (puzzle[i]-1)/3);
      yokocost = zettaichi((i+2)%3 - (puzzle[i]+2)%3);
	
	totalcost += tatecost + yokocost;
    }
  }

  return totalcost;
}

void printpuzzle(int *puzzle)
{
  int i, j, number = 1;
  
  for(i = 0; i < N; i++) {
    for(j = 0; j < N; j++) {
      printf(" %d",puzzle[number]);
      number++;
    }
    printf("\n");
  }
  
}

int dfs(int *puzzle)
{
  int i;

  while(1) {
    if(visit(puzzle, 0) == FOUND) break;
    d++;
  }

  return i;
}

int visit(int *puzzle, int g)
{
  int i, blanknumber, status, found;
  int copypuzzle[NN+1];

  found = 1;
  for(i = 1; i <= NN; i++) {
    if(puzzle[i] != goal[i]) {
      found = 0;
      break;
    }
  }
  if(found == 1) {
    printf("%d\n",g);
    return FOUND;
  }
  
  if(g + heuristic(puzzle) > d) return BACK;

  //空白位置の確認
  for(i = 1; i <= NN; i++) {
    if(puzzle[i] == 0) {
      blanknumber = i;
      break;
    }
  }

  //0を下と交換
  if((blanknumber-1)/3 != 2) {
    puzzlecopy(puzzle, copypuzzle);
    copypuzzle[blanknumber] = copypuzzle[blanknumber+3];
    copypuzzle[blanknumber+3] = 0;
    if(visit(copypuzzle, g+1) == FOUND) return FOUND;
  }

  //0を右と交換
  if((blanknumber+2)%3 != 2) {
    puzzlecopy(puzzle, copypuzzle);
    copypuzzle[blanknumber] = copypuzzle[blanknumber+1];
    copypuzzle[blanknumber+1] = 0;
    if(visit(copypuzzle, g+1) == FOUND) return FOUND;
  }

  //0を左と交換
  if((blanknumber+2)%3 != 0) {
    puzzlecopy(puzzle, copypuzzle);
    copypuzzle[blanknumber] = copypuzzle[blanknumber-1];
    copypuzzle[blanknumber-1] = 0;
    if(visit(copypuzzle, g+1) == FOUND) return FOUND;
  }

  //0を上と交換
  if((blanknumber-1)/3 != 0) {
    puzzlecopy(puzzle, copypuzzle);
    copypuzzle[blanknumber] = copypuzzle[blanknumber-3];
    copypuzzle[blanknumber-3] = 0;
    if(visit(copypuzzle, g+1) == FOUND) return FOUND;
  }

  return BACK;
}


int zettaichi(int x)
{
  if(x < 0) x = -x;
  return x;
}

void puzzlecopy(int *puzzle, int *copypuzzle)
{
  int i;
  
  for(i = 1; i <= NN; i++) {
    copypuzzle[i] = puzzle[i];
  }
}






Measured memory_bytes: 2148