akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF INT_MAX
vi seg;
int n;

void update(int index, int x) {
  seg[n + index] += x;
  for (int i = n + index; i >= 2; i /= 2) {
    seg[i/2] = seg[i] + seg[i^1];
  }
}

// seg[k] : [l, r)
int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) {
    return 0;
  }
  if (a <= l && r <= b) {
    return seg[k];
  } else {
    return query(a, b, k*2, l, (l+r)/2) + query(a, b, k*2+1, (l+r)/2, r);
  }
}

int main() {
  int n_, q;
  scanf("%d %d", &n_, &q);
  n = (1 << (int)(ceil(log2(n_))));
  seg.assign(2*n, 0);
  int c, x, y;
  rep (i, q) {
    scanf("%d %d %d", &c, &x, &y);
    x -= 1;
    if (c == 0) {
      update(x, y);
    } else {
      printf("%d\n", query(x, y, 1, 0, n));
    }
  }

  return 0;
}

Measured memory_bytes: 4076
main :: IO ()
main = do
    line <- getLine
    putStrLn $ solve line

solve :: String -> String
solve line = show n
    where
        x = read line :: Int
        n = 2 * k + m + 1
        k = (x - 1) `div` 11
        m = maybePlusOne x

maybePlusOne :: Int -> Int
maybePlusOne x
    | (x-1) `mod` 11 < 6    = 0
    | otherwise             = 1


Measured memory_bytes: 508
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  string S;
  cin>>S;
  int n = S.size();

  int tcount=0;
  for(int i=n-1; i>-1; --i){
    if(tcount && S[i]=='S') --tcount;
    if(S[i]=='T') ++tcount;
  }
  cout<<2*tcount<<endl;


  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		int p1=0,p2=0;
		
		
		
		
		Arrays.sort(a);
		p1 = a[0];
		for (int i = 1; i < a.length; i++) {
			int j = a[i];
			if (p1>p2) {
				p2+=j;
			}else {
				p1+=j;
			}
		}
		
		int ans = Math.abs(p1-p2);
		out.println(ans);
		out.close();
	}

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------

}



Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h+2);
  for(int i=0;i<w+2;i++){
    s.at(0)+='.';
    s.at(h+1)+='.';
  }
  for(int i=1;i<h+1;i++){
    s.at(i)='.';
    string t;
    cin >> t;
    s.at(i)+=t;
    s.at(i)+='.';
  }
  
  int ans=1;
  
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(s.at(i).at(j)=='#'){
        ans*=(s.at(i+1).at(j)=='#'||s.at(i-1).at(j)=='#'||s.at(i).at(j+1)=='#'||s.at(i).at(j-1)=='#');
      }
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
LL sum[qq];

int main(){
	int n;	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%lld", sum + i);
		sum[i] += sum[i - 1];
	}
	LL minx = 1e18;
	for(int i = 1; i < n; ++i){
		minx = min(minx, abs(sum[i] - (sum[n] - sum[i])));
	}
	printf("%lld\n", minx);
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;
        
/* 
const ll MAX_MEM = 25e7;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

signed main()
{
    Start();
    int ans = 0;
    int n;
    cin >> n;
    vector <int> a(n);
    cin >> a;
    vector <int> b;
    b.pb(0);
    for (auto &i : a)
    {
        if (!i)
            b.pb(0);
        else
            b.back() += i;
    }
    for (int i : b)
        ans += i / 2;
    cout << ans;
    return 0;
}
 


Measured memory_bytes: 2168
#include <iostream>
using namespace std;
int main(){
  int N, dif, max=0, min=1000000000;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++){
    if(max<A[i])max=A[i];
    if(min>A[i])min=A[i];
  }
  dif=max-min;
  cout<<dif<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    vector<pii> cb(m);
    REP(i,m) {
        cin >> cb[i].second >> cb[i].first;
    }
    sort(ALL(a));
    sort(RALL(cb));
    int i = 0, j = 0;
    while(j < m) {
        REP(k,cb[j].second) {
            if (i >= n || cb[j].first <= a[i]) break;
            a[i] = cb[j].first;
            i++;
        }
        j++;
    }

    ll ans = accumulate(ALL(a),0LL);

    cout << ans << '\n';

    return 0;
}

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

if n == 0:
    print(0)
    exit()

else:
    ans = []
    r = 1
    while n != 0:
        if n % (r*-2) == 0:
            ans.append('0')
        else:
            ans.append('1')
            n -= r
        r *= -2
print(''.join(reversed(ans)))

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))[::-1]
if a[0]!=2:
    print(-1)
    exit()
import math
#print(a)
maxi=3
mini=2
for i in range(1,n):
    if mini<=a[i]:
        mini=a[i]
    else:
        times=math.ceil(mini/a[i])
        mini=a[i]*times
    if mini>maxi:
        print(-1)
        exit()
    #print("i={} mini={}".format(i,mini))
    if maxi<a[i]:
        print(-1)
        exit()
    else:
        times=int(maxi/a[i])
        maxi=a[i]*(times+1)-1
    #print("i={} maxi={}".format(i,maxi))
print(mini,maxi)

Measured memory_bytes: 14436
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double
#define f(i,x,y,z) for(int i=x;i<y;i+=z)
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
ll gcd(ll,ll);
ll lcm(ll,ll);
bool prime(ll x);
ll fp(ll b,ll p,ll m);
ll inv(ll a,ll m);
int primes(ll n){
    int ans=0;
    for(int i=2;i<=sqrt(n);i++){
        int count=0;
        while(n%i==0){
            n=n/i;
            count++;
        }
        if(count>0){
            int x=1;
            int inc=1;
            while(x+inc+1<=count){
                inc++;
                x+=inc;
            }
            ans+=inc;
        }
    }
    if(n>1){
        ans+=1;
    }
    return ans;
}
int main(){
    fast;
    ll n;
    cin>>n;
    cout<<primes(n)<<'\n';
}
ll gcd(ll x,ll y) { return (y==0)? x: gcd(y,x%y);}
ll lcm(ll x, ll y) { return (x*y)/gcd(x,y);}
ll inv(ll a,ll m){return fp(a,m-2,m);}
bool prime(ll x){
    if(x<2) return false;
    if(x<4) return true;
    if(x%2==0 or x%3==0) return false;
    f(i,5,sqrt(x)+1,6)
        if(x%i==0 or x%(i+2)==0) return false;
    return true;
}
ll fp(ll b,ll p,ll m){
    b%=m;
    ll res=1;
    while(p>0){
        if(p%2==1)
            res=(res*b)%m;
        b=(b*b)%m;
        p=p/2;
    }
    return res%m;
}

Measured memory_bytes: 3700
#include <iostream>

using namespace std;

int main(void)
{
    int N, d[50], i, j, sum=0;

    cin >> N;

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

    for(i=0; i<N-1; i++){
        for(j=i+1; j<N; j++){
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N, K;
    cin >> N >> K;
    vector<int> calc(1001, 0);
    for (int i = 1; i <= 1000; ++i) {
        calc.at(i) = calc.at(i - 1) + i;
    }
    vector<double> exv(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        int p;
        cin >> p;
        exv.at(i) = exv.at(i - 1) + 1.0 * calc.at(p) / p;
    }

    double ans = 0;
    for (int i = K; i <= N; ++i) {
        double res = exv.at(i) - exv.at(i - K);
        ans = max(ans, res);
    }

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int a,b,c,x,i,j,k,total,count=0;
  scanf("%d %d %d %d",&a,&b,&c,&x);
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        total=500*i+100*j+50*k;
        if(total==x){count++;}
      }
    }
  }
  printf("%d\n",count);
}

Measured memory_bytes: 128
import collections
n,m = map(int, input().split())
ps = [list(input().split()) for _ in range(m)]

q = [0]*n
t = [0]*n

for [p,s] in ps:
    p = int(p) - 1
    if s == "AC" and q[p] == 0:
        q[p] += 1
    elif s == "WA" and q[p]== 0:
        t[p] += 1


"""
for [u,r] in ps:
    u = int(u) -1
    if q[u] == 0 and t[u] != 0:
        t[u] == 0
"""

w = 0
for i, uc in enumerate(q):
    if uc == 1:
        w += t[i]
    


print(sum(q),w)


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

long long int pot5(long long int n) {
    return n * n * n * n * n;
}

int main() {
    int x;
    cin >> x;
    long long int pot[121];
    for (int i = 0; i <= 120; i++) {
        pot[i] = pot5((long long int) i);
    }
    for (int i = 1; i <= 120; i++) {
        long long int fix = pot[i];
        for (int j = 0; j < i; j++) {
            if (fix - pot[j] == x) {
                cout << i << " " << j << endl;
                return 0;
            } else if (fix + pot[j] == x) {
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }  
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<int> data;
	ff(i, 0, n) {
		int x;
		cin >> x;
		data.push(x);
	}
	ff(i, 0, m) {
		int y = data.top();
		data.pop();
		y /= 2;
		data.push(y);
	}
	i64 ans = 0;
	while (!data.empty()) {
		ans += data.top();
		data.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include<cstdio>
const int MaxN=200010;
int N;
struct edge{int to;edge*next;}E[MaxN*2],*ne=E,*fir[MaxN];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
char s[MaxN];
int fa[MaxN],siz[MaxN],dn[MaxN],dn2[MaxN],up[MaxN];
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void dfs_dn(int i){
	dn[i]=dn2[i]=0;
	siz[i]=s[i]=='1';
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
		fa[e->to]=i;
		dfs_dn(e->to);
		siz[i]+=siz[e->to];
		if(dn[e->to]+1>dn[i])dn2[i]=dn[i],dn[i]=dn[e->to]+1;
		else dn2[i]=max(dn2[i],dn[e->to]+1);
	}
}
void dfs_up(int i){
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
		up[e->to]=max(up[i],dn[i]==dn[e->to]+1?dn2[i]:dn[i])+1;
		dfs_up(e->to);
	}
}
int main(){
	scanf("%d",&N);
	for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(--u,--v),link(v,u);
	scanf("%s",s);
	fa[0]=-1;
	dfs_dn(0);
	dfs_up(0);
	long long ans=1;
	for(int i=0;i<N;i++){
		int len=1,mx=0,se=0,md=N;
		if(s[i]=='1')md=0;
		for(edge*e=fir[i];e;e=e->next){
			int sz,d;
			if(e->to==fa[i])sz=siz[0]-siz[i],d=up[i];
			else sz=siz[e->to],d=dn[e->to]+1;
			if(d>mx)se=mx,mx=d;
			else se=max(se,d);
			if(sz&&d<md)md=d;
		}
		mx=min(mx,se+2);
		ans+=max(mx-md,0);
	}
	printf("%lld\n",ans);
}

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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair

typedef long long llong;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< vi > vvi;

void solve(){

	int n, m;
	cin >> n >> m;

	vector<int> cnt(n, 1);
	vector<bool> red(n);
	red[0] = true;

	for(int i = 0; i < m; i++){

		int a, b;
		cin >> a >> b;
		a--; b--;


		cnt[a]--;
		cnt[b]++;
		
		if(red[a]){
			red[b] = true;
		}

		if(cnt[a] == 0){
			red[a] = false;
		}

	}

	int ans = 0;

	for(bool b : red){
		ans += b ? 1 : 0;
	}

	cout << ans;


}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	if(a==b && a!=c && b!=c){
		printf("Yes\n");
	}
	else if(c==b && a!=c && b!=a){
		printf("Yes\n");
	}
	else if(a==c && a!=b && b!=c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

namespace ABC069B_cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.Write(s[0]);
            Console.Write(s.Length - 2);
            Console.WriteLine(s[s.Length - 1]);
        }
    }
}


Measured memory_bytes: 13140
def main(N, aa):
    """
    a_i * a_(i+1) = 4k
        i=2n and i+1=2m
        i=4n or  i+1=4m

    half: 4m -> ok
    all: 2n -> ok

    example5
        2 7 1 8 2 8
          -     -
        2 2 1 8 7 8
    all2を作成
    残りhalfのパターン

    example2
        1 2 3 4
        2 1 3 4
          1 3 4

        all2, 最後の１つは２＊２にならないので以下でフォロー
        2, 4m, x, 4m
        2, 4m, x, 4m, x
    """
    n_m2 = 0
    n_m4 = 0
    n_m2_notm4 = 0
    for a in aa:
        is_m2 = a % 2 == 0
        is_m4 = a % 4 == 0

        n_m2 += int(is_m2)
        n_m4 += int(is_m4)
        n_m2_notm4 += int(is_m2 and not is_m4)

    if n_m2 == N:
        return "Yes"
    elif n_m2_notm4 == 0 and n_m4 >= N // 2:
        return "Yes"
    else:
        rest = N - n_m2_notm4 + 1
        if n_m4 >= rest // 2:
            return "Yes"
        else:
            return "No"


if __name__ == '__main__':
    N = int(input())
    aa =map(int, input().split())

    print(main(N, aa))


Measured memory_bytes: 11052
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int cnt=0;
	for(int i=0;i<n;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			cnt++;
		} 
	}
	cout<<cnt;
	return 0;
} 

Measured memory_bytes: 384
#include<stdio.h>

#define N 100

int main(){
  int M[N][N],n,u,k,v,i,j;

  scanf("%d",&n);
 for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;

    for(j=0;j<k;j++){
       scanf("%d",&v);
       v--;
       M[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}


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


int main()
{
	int a1,a2,a3,maxNum,midNum,minNum;
	cin >> a1 >> a2 >> a3;
	maxNum = max(a1, max(a2, a3));
	minNum = min(a1, min(a2, a3));
	if (a1 >= a2) {
		if (a3 <= a1)midNum = a1;
		else if (a3 >= a2)midNum = a2;
		else midNum = a3;
	}
	else if (a1 < a2) {
		if (a3 <= a2)midNum = a2;
		else if (a3 >= a1)midNum = a1;
		else midNum = a3;
	}
	cout << abs(maxNum -midNum) + abs(midNum - minNum) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int a, b, c;
  int d = 0;
  int e = 0;
  cin >> a >> b >> c;
  //cout << a << " " << b << " " << c << endl;
  d = a;
  a = b;
  b = d;
  //cout << a << " " << b << " " << c << endl;
  e = a;
  a = c;
  c = e;
  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  cout<<((a==c)? 0:1)<<endl;

  return 0;
}

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

#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define bitcount    __builtin_popcountll
#define si(x)       scanf("%d",&x)
#define su(x)       scanf("%u",&x)
#define sll(x)      scanf("%lld",&x)
#define sl(x)       scanf("%ld",&x)     
#define sc(x)       scanf("%c",&x)
#define ss(x)       scanf("%s",x)
#define sf(x)       scanf("%f",&x)
#define slf(x)      scanf("%lf",&x)
#define pri(x)      printf("%d\n",x)
#define prl(x)      printf("%lld\n",x)
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define pll         pair<long long,long long>
#define pil         pair<int,long long>
#define pli         pair<long long,int>
#define vi          vector<int>
#define vl          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<=b;i++)
#define repl(i,a,b) for(long long i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define rrepl(i,a,b) for(long long i=a;i>=b;i--)
#define M           1000000007

const int maxn=1e6+100;

ll pw2(ll a,ll b){
    if(b==0) return 1;
    ll temp=pw2(a,b/2);
    if(!(b%2)) return temp*temp;
    return a*temp*temp;
}

void solve(){
    ll n,p,k,z,y,x,m;
    sll(n); sll(m);
    k=pw2(2,m);
    ll ans=100*n+1800*m;
    ans*=k;
    prl(ans);
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;
    //si(t);
    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 256
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		string s;
		cin>>s;
		if(count(ALL(s),'A')&&count(ALL(s),'B'))
			cout<<"Yes";
		else
			cout<<"No";
		cout<<endl;
	}

	return 0;
}

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

const int INF = 1e9;

int main() {
  long long X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  long long a[X],b[Y],c[Z];

  for(int i=0;i<X;i++) {
    cin>>a[i];
  }
  for(int i=0;i<Y;i++) {
    cin>>b[i];
  }
  for(int i=0;i<Z;i++) {
    cin>>c[i];
  }

  long long tmp[X*Y];
  for(int i=0;i<X;i++) {
    for(int j=0;j<Y;j++){
      tmp[Y*i+j] = a[i]+b[j];
    }
  }
  sort(tmp,tmp+X*Y,greater<long long>());

  int n=min(K,X*Y);
  long long result[n*Z];
  for(int i=0;i<n;i++) {
    for(int j=0;j<Z;j++){
      result[Z*i+j]=tmp[i]+c[j];
    }
  }
  sort(result,result+n*Z,greater<long long>());
  for(int i=0;i<K;i++) {
    cout<<result[i]<<endl;
  }


}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}


int main(){
  string s;
  cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#define N 100000
#define NIL -1
int Depth(int );
void display(int );
int getsibling(int );
int getheight(int );
struct Node {
  int parent;
  int left;
  int right;
};

struct Node T[N];
int n,D[N];

int main()
{
  int a,b,c,i,l,m;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      T[i].parent=NIL;
      T[i].left=NIL;
      T[i].right=NIL;
    }
  
  for(i=0;i<n;i++)
    {
      scanf("%d%d%d",&a,&b,&c);
      T[a].left=b;
      T[a].right=c;
      if(b!=NIL) T[b].parent=a;
      if(c!=NIL) T[c].parent=a;
    }
  for(i=0;i<n;i++)
    {
      D[i]=Depth(i);
    }
  for(i=0;i<n;i++)
    {
      display(i);
    }
  return 0;
}

int Depth(int a)
{
  int d=0;
  while(T[a].parent!=-1)
    {
      a=T[a].parent;
      d++;
    }
  return d;
}
int getsibling(int x)
{
  if(T[x].parent==NIL) return NIL;
  if(T[T[x].parent].left!=x&&T[T[x].parent].left!=NIL) return T[T[x].parent].left;
  if(T[T[x].parent].right!=x&&T[T[x].parent].right!=NIL) return T[T[x].parent].right;
  else return NIL;
}
int getheight(int x)
{
  int height1=0,height2=0;
  if(T[x].left!=NIL) height1=getheight(T[x].left)+1;
  if(T[x].right!=NIL) height2=getheight(T[x].right)+1;
  if(height1>=height2) return height1;
  else return height2;
}
void display(int x)
{
  int i,j,deg=0;
  if(T[x].left!=NIL) deg++;
  if(T[x].right!=NIL) deg++;
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",x,T[x].parent,getsibling(x),deg,D[x],getheight(x));
  if(T[x].parent==NIL) printf("root\n");
  else if(T[x].left==NIL&&T[x].right==NIL) printf("leaf\n");
  else printf("internal node\n");  
}

Measured memory_bytes: 2756
N,K = map(int,input().split())

nij = []

for i in range(K):
    if 2 ** (i+1) >= K * 4:
        break
    nij.append(2 ** i )
    
ans = 0
cur = len(nij)-1

for i in range(N):
    for j in range(len(nij)):
        #print(i,j,nij[cur-j])
        if nij[cur-j]*(i+1) >= K and nij[cur-j-1]*(i+1) < K:
            #print(cur-j,nij[cur-j],0.5 ** (cur-j+1) )
            ans = ans + 1 / N * 0.5 ** (cur-j)
            #print(i+1)
            break
            #print(1 / N * 0.5 ** (cur-j))
        elif (i+1) >= K:
            ans = ans + 1 / N
            #print(i+1)
            break

print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var (
		N, Q, l, r int
		S          string
	)
	fmt.Scan(&N, &Q, &S)

	cnt := make([]int, N+1)
	for i := 0; i < N; i++ {
		if i+1 < N && string(S[i]) == "A" && string(S[i+1]) == "C" {
			cnt[i+1] = cnt[i] + 1
		} else {
			cnt[i+1] = cnt[i]
		}
	}

	for i := 0; i < Q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(cnt[r-1] - cnt[l-1])
	}
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> v(1, 0);
    for (ll i = 0; i < n; i++)
    {
        ll t;
        cin >> t;
        v.push_back(v.back() + t);
    }
    ll m = LLONG_MAX;
    for (ll i = 1; i < n; i++)
    {
        m = min(m, abs(v.back() - v[i] * 2));
    }
    cout << m << endl;
}

Measured memory_bytes: 2420
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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 MOD = 1e9 + 7;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 100020;

int F(int x, int y) {
	int c1 = 0, c2 = 0;
	while (x > 0) {
		c1++, x /= 10;
	}
	while (y > 0) {
		c2++; y /= 10;
	}
	return max(c1, c2);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N; cin >> N;
	ll ans = 10000;
	for (int i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ans = min(ans, F(i, N / i));
		}
	}
	print(ans);
}



Measured memory_bytes: 256
import math
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
color = [-1]*n
edge = [list() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

flag = True


def dfs(i, pre, c):
    if color[i] == c:
        return
    elif color[i] == 1-c:
        global flag
        flag = False
        return
    color[i] = c
    for v in edge[i]:
        dfs(v, i, 1-c)


dfs(0, -1, 0)
# print(color)
# print(flag)

if flag:
    print(color.count(1)*color.count(0)-m)
else:
    print(math.floor(n*(n-1)/2-m))


Measured memory_bytes: 43944
#include <bits/stdc++.h>
#define N 200005
using namespace std;

int n, a[N], p[N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i), p[a[i]] = i;
    int last = 1, ans = 1;
    for (int i = 2; i <= n + 1; ++i)
        if (p[i] < p[i - 1]) ans = max(ans, i - last), last = i;
    cout << n - ans << endl;
    return 0;
}


Measured memory_bytes: 1792
while(True) :
    H,W=map(int,input().split())
    if H==0 and W==0 : break
    for i in range(H) :
        for j in range(W) :
            if i==0 or i==H-1 or j==0 or j==W-1 :
                print("#",end="")
            else :
                print(".",end="")
        print("")
    print("")


Measured memory_bytes: 7008
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int cnt = 0;
    for(int i=0; i<N-1; i++){
      for(int j=i+1; j<N; j++){
        cnt++;
      }
    }
    for(int i=0; i<M-1; i++){
      for(int j=i+1; j<M; j++){
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 35852
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<stw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

int main(void){
    int N,M;cin>>N>>M;
    vector<int> digit(N+1,-1);
    int s = 0;
    int alt = 0;
    int ans = 0;
    int end = 0;
    for(int i=0;i<M;i++){
        cin >> s;
        alt = digit[s];
        cin >> digit[s];
        if(alt!=-1&&alt!=digit[s]){
            end = 1;
        }
        if(digit[1]==0&&N!=1){
            end = 1;
        }else if(digit[1]==0&&N==1){
            end = 2;
        }
    }
    if(end==1){
        cout << -1 << endl;
    }else if(end==2){
        cout << 0 << endl;
    }else{
        for(int i=1;i<=N;i++){
            if(digit[i]==-1){
                if(i==1){
                    digit[i] = 1;
                }else{
                    digit[i] = 0;
                }
            }
        }
        for(int i=1;i<=N;i++){
            ans += digit[i]*pow(10,N-i);
        }
        if(M!=0){
            cout << ans << endl;
        }else if(M==0){
            if(N==1){
                cout << 0 << endl;
            }else{
                cout << pow(10,N-1);
            }
        }
    }
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

   int N;
   cin>>N;
   vector<int>L(N);
   for(int i=0;i<N;i++)cin>>L[i];
   sort(rrng(L));
   int m = L[0];
   L.erase(L.begin());
   int sum=0;
   for(int i=0;i<N-1;i++)sum+=L[i];
   if(m<sum)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>




int main()
{

	int A=0,B=0,H=0,M=0;
	long double thetaA=0,thetaB=0,x=0;
	long double pi= 3.141592653589;
	
	scanf("%d %d %d %d",&A,&B,&H,&M);
	
//	thetaA=(60*H+M)*M_PI/360;
//	thetaB=M*M_PI/30;
	
	x=sqrt(A*A+B*B-2*A*B*cos((60*H-11*M)*pi/360));
	
	printf("%.20Lf",x);
	
	
	return 0;
}


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

using namespace std;
long int n;
int main()
{
    cin>>n;
    long long a[n+2];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    a[0]=a[1];
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<a[i-1])
        {
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<sum;
}


Measured memory_bytes: 5152
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <limits>

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
struct Graph {
    std::vector<std::vector<Edge<Cost>>> graph;

    Graph(int n = 0) : graph(n) {}

    void span(bool direct, int src, int dst, Cost cost = 1) {
        graph[src].emplace_back(src, dst, cost);
        if (!direct) graph[dst].emplace_back(dst, src, cost);
    }

    std::vector<Edge<Cost>>& operator[](int v) { return graph[v]; }
    std::vector<Edge<Cost>> operator[](int v) const { return graph[v]; }

    int size() const { return graph.size(); }
};

template <class Cost>
std::vector<Cost> dijkstra(const Graph<Cost>& graph, int s) {
    constexpr Cost INF = std::numeric_limits<Cost>::max();

    std::vector<Cost> dist(graph.size(), INF);
    dist[s] = 0;
    MinHeap<std::pair<Cost, int>> que;
    que.emplace(0, s);

    while (!que.empty()) {
        int v;
        Cost d;
        std::tie(d, v) = que.top();
        que.pop();
        if (d > dist[v]) continue;

        for (const auto& e : graph[v]) {
            if (dist[e.dst] <= dist[v] + e.cost) continue;
            dist[e.dst] = dist[v] + e.cost;
            que.emplace(dist[e.dst], e.dst);
        }
    }

    return dist;
}

using lint = long long;
constexpr int C = 50 * 100;

void solve() {
    int n, m, s;
    std::cin >> n >> m >> s;
    s = std::min(s, C);

    auto enc = [&](int v, int c) { return v * (C + 1) + c; };

    Graph<lint> graph(n * (C + 1));
    while (m--) {
        int u, v, a, b;
        std::cin >> u >> v >> a >> b;

        --u, --v;
        a = std::min(a, C);

        for (int c = 0; c + a <= C; ++c) {
            graph.span(true, enc(u, c + a), enc(v, c), b);
            graph.span(true, enc(v, c + a), enc(u, c), b);
        }
    }

    for (int v = 0; v < n; ++v) {
        for (int i = 1; i <= C; ++i) {
            graph.span(true, enc(v, i), enc(v, i - 1), 0);
        }

        int c, d;
        std::cin >> c >> d;
        c = std::min(c, C);

        for (int i = 0; i + c <= C; ++i) {
            graph.span(true, enc(v, i), enc(v, i + c), d);
        }
    }

    auto ds = dijkstra(graph, enc(0, s));
    for (int v = 1; v < n; ++v) {
        std::cout << ds[enc(v, 0)] << std::endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 48956
S = input()

ans = 0
for i in range(len(S)):
    cnt = 0
    for j in range(i, len(S)):
        if S[j] in ['A', 'C', 'G', 'T']:
            cnt += 1
        else:
            break
    ans = max(ans, cnt)
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
 
#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

int n, m, x;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> x;
    vector <vector <int> > a(n, vector <int>(m) );
    int c[n];
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++) cin >> a[i][j];
    }
    int mask = 1 << n;
    ll mn = INF;
    for(int sub = 0; sub < mask; sub++){
        vector <int> level(m, 0);
        ll temp = 0;
        for(int j = 0; j < n; j++){
            if(!(sub & (1 << j)))
                continue;
            temp += c[j];
            for(int k = 0; k < m; k++)
                level[k] += a[j][k];
        }
        bool flag = false;
        for(int j = 0; j < m; j++)
            if(level[j] < x)
            {flag = true; break;}
        if(flag)
            continue;
        mn = min(mn, temp);
    }
    cout << (mn == INF ? -1 : mn)  << endl;
	return 0;
}


Measured memory_bytes: 3628
import math

def comb(a,b):
  return math.factorial(a)//((math.factorial(b)*math.factorial(a-b)))

N=int(input())
a=list(map(int,input().split()))

a.sort()
a_max=a[-1]
a=a[:-1]
#print(a)

b = [[abs(i+(-a_max//2)),i] for i in a]
b.sort()
print(a_max, b[0][1])

Measured memory_bytes: 20792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int main(){
    ll n; cin >> n;
    ll ans = n*(n-1)/2;
    cout << ans << endl;
}

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


int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A, A+3);
  int A0 = A[0];
  for (int i=0;i<3;i++) A[i] -= A0;
  
  int retval = 0;
  if (A[1]%2==1){
    retval++;
    if (A[2]%2){
      A[1]++;
      A[2]++;
    }
    else {
      A[0]++;
      A[2]++; 
    }
  }
  else {
    if (A[2]%2){
      retval++;
      A[0]+=1;
      A[1]+=1;
    }
    
  }
  retval += (A[2]-A[1])/2 + (A[2]-A[0])/2;
  cout << retval << endl;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
long long dis[10002];
bool vis[10002];
vector<int> a[10002];
vector<int> b[10002];
int n,u,k,x,t=1,w,m,s,v;
queue<int> q;
int main(){
	cin>>n;
	memset(vis,false, sizeof(vis));
	memset(dis,0x1f1f1f1f,sizeof(dis));
	for (int i=0; i<n; i++){
		cin>>u>>k;
		while (2*k--){
			  cin>>v>>w;
			  a[u].pb(v);
		      b[u].pb(w);
		}
	}
	q.push(0);
	dis[0]=0;
	while (!q.empty()){
		  x=q.front(); q.pop(); vis[x]=false;
		  for (int i=0; i<a[x].size(); i++){
		  	  if (dis[a[x][i]]>dis[x]+b[x][i]){
		  	  	  dis[a[x][i]]=dis[x]+b[x][i];
		  	  	  if (!vis[a[x][i]]){
		  	  	  	  vis[a[x][i]]=true;
		  	          q.push(a[x][i]);
                  }
			 }
		  	  
		  }
	}
    for (int i=0; i<n; i++){
		cout<<i<<' '<<dis[i]<<'\n';
	}
	return 0;
}


Measured memory_bytes: 8292
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define N 100005
#define inf 1000000000
#define MOD 998244353
#define sz(x) ((int)x.size())
#define umax(x,y) x=max(x,y)
using namespace std;

int n;
multiset<int> R,G,B;
char s[3*N];
int a[3*N];

int mul(int x,int y) {
	
	return (ll)x*y%MOD;

}

int fac(int n) {

	int res=1;

	for(int i=2;i<=n;i++) res=mul(res,i);

	return res;

}

int main(int arg,char* argv[]) {

	scanf("%d",&n);

	scanf("%s",s+1);

	for(int i=1;i<=3*n;i++) {

		if(s[i]=='R') R.insert(i);
		if(s[i]=='G') G.insert(i);
		if(s[i]=='B') B.insert(i);

	}

	while(sz(R)) {

		vector<int> ps;

		int Rp=*R.begin();
		int Gp=*G.begin();
		int Bp=*B.begin();

		ps.pb(Rp);
		ps.pb(Gp);
		ps.pb(Bp);

		R.erase(R.begin());
		G.erase(G.begin());
		B.erase(B.begin());

		sort(ps.begin(),ps.end());

		a[ps[0]]=0;
		a[ps[1]]=1;
		a[ps[2]]=2;

	}

	int ans=fac(n);
	int cnt_p=0,cnt_m=0;

	for(int i=3*n;i>=1;i--) {

		if(a[i]==2) {

			cnt_p++;

		}
		else if(a[i]==1) {

			ans=mul(ans,cnt_p);
			cnt_p--;
			cnt_m++;

		}
		else {

			ans=mul(ans,cnt_m);
			cnt_m--;

		}

	}

	printf("%d",ans);

}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1LL*x*p.x%mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this*=p.inverse();
        return *this;
    }
    ModInt operator-()const{return ModInt(-x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
    bool operator==(const ModInt &p)const{return x==p.x;}
    bool operator!=(const ModInt &p)const{return x!=p.x;}
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            swap(a,b);
            u-=t*v;
            swap(u,v);
        }
        return ModInt(u);
    }
    friend ostream &operator<<(ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend istream &operator>>(istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};

const int mod=1e9+7;
using mint=ModInt<mod>;
int main(){
    int n,m;
    cin>>n>>m;
    vector<string> vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    mint dp[n][m];
    dp[0][0]=1;
    REP(i,n){
        REP(j,m){
            if(i+1<n&&vec[i+1][j]=='.'){
                dp[i+1][j]+=dp[i][j];
            }
            if(j+1<m&&vec[i][j+1]=='.'){
                dp[i][j+1]+=dp[i][j];
            }
        }
    }
    cout<<dp[n-1][m-1]<<endl;
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N, W;
    cin >> N >> W;
    vector<lint> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    vector<vector<lint>> ma(N + 1, vector<lint>(W + 1, -INF));
    ma[0][0] = 0;
    for (int j = 1; j <= W; j++) {
        ma[0][j] = -INF;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            ma[i][j] = ma[i - 1][j];
            if (j - w[i - 1] >= 0) {
                ma[i][j] = max(ma[i][j], ma[i - 1][j - w[i - 1]] + v[i - 1]);
            }
        }
    }
    lint ans = -1;
    for (int j = 0; j <= W; j++) {
        ans = max(ans, ma[N][j]);
    }
    cout << ans << endl;

    // dump(v);
    // dump(w);
    // ddump(ma);
    return 0;
}

Measured memory_bytes: 83036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 501, MAX_M = 2e5+10;
int N, M, Q;
int L[MAX_M], R[MAX_M];
int p[MAX_M], q[MAX_M];
ll ans[MAX_N][MAX_N];

void solve()
{
	for(int i=0;i<M;++i){
		for(int le=1;le<=L[i];++le)ans[le][R[i]]++;
	}
	for(int i=1;i<=N;++i)for(int j=1;j<=N;++j){
        ans[i][j] += ans[i][j-1];
	}
	for(int i=0;i<Q;++i){
		cout << ans[p[i]][q[i]] << '\n';
	}
}

int main()
{
	cin >> N >> M >> Q;
	for(int i=0;i<M;++i) cin >> L[i] >> R[i];
	for(int i=0;i<Q;++i) cin >> p[i] >> q[i];
	solve();
	return 0;
}

Measured memory_bytes: 7816
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    vector<int> as(n);
    for (auto &a: as) scanf("%d", &a);

    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        if (i > 0 && as[i - 1] > 0 && as[i] > 0) {
            ans++;
            as[i - 1] --;
            as[i] --;
        }

        ans += as[i] / 2;
        as[i] %= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char ans[52][52];
int fx[4] = {1,0,-1,0};
int fy[4] = {0,1,0,-1};
int main(){
  memset(ans,'.',sizeof(ans));
  int m,n;
  cin>>m>>n;
  string sen;
  getchar();
  for(int i = 0;i<m;i++){
    getline(cin,sen);
    for(int j = 0;j<n;j++){
        ans[i][j] = sen[j];
    }
  }
  int cnt = 0;
  for(int i = 0;i<m;i++){
    for(int j = 0;j<n;j++){
            cnt = 0;
    if(ans[i][j] == '#'){
        for(int k = 0;k<4;k++){
            int tx = i+fx[k];
            int  ty = j + fy[k];
            if(tx>=0&&ty>=0&&tx<m&&ty<n){
               if(ans[tx][ty] == ans[i][j])cnt++;
            }
        }
        if(cnt == 0){cout<<"No"<<endl;return 0;}
    }
    }
  }

  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256