akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 500005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll x = 0,y = 0,nx,ny,now = 0,t;
    bool ok = 1;
    rep(i,n){
        cin >> t;
        cin >> nx >> ny;
        ll k = abs(x-nx)+abs(y-ny);
        if ((t-now)%2 != k%2 || k > t-now){
            ok = 0;
        }
        now = t;
        x = nx;
        y = ny;
    }
    Yes(ok);
}


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

int main(){
  string s;
  cin>>s;
  long long int k;
  cin>>k;
  for(int i=0;i<s.size()-1;i++){
    if(s[i]!='a'&&26-(s[i]-'a')<=k){
      k-=26-(s[i]-'a');
      s[i]='a';
    }
  }
  k%=26;
  if(s[s.size()-1]-'a'>25-k)k-=26;
  s[s.size()-1]+=k;
  cout<<s<<endl;
}


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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    vector<int> time(3);
    int sum = 0;

    f(i, 3) {
        cin >> time.at(i);
    }

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

    cout << time.at(0) + time.at(1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

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

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/********** TEMPLATE ENDS HERE ***********/

main()
{
	IOS
	
	string s;
	cin >> s;
	
	cout << s[0];
	
	cin >> s;
	
	cout << s[1];
	
	cin >> s;
	
	cout << s[2];
}

Measured memory_bytes: 256
use std::io::stdin;

fn beginning_with_capital_a(input: &str) -> bool {
    input.chars().next().unwrap() == 'A'
}

fn intermediate_capital_c(input: &str) -> bool {
    input[2..input.len()-1].chars().any(|c| c == 'C')
}

fn exactly_two_capitals(input: &str) -> bool {
    input.chars().map(|c| c.is_uppercase() as i32).fold(0 as i32, |x, y| x + y) == 2
}

fn main () {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let input = buf.trim_right();

    let condition = beginning_with_capital_a(input) && intermediate_capital_c(input) && exactly_two_capitals(input);
    let ans = if condition { "AC" } else { "WA" };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int n;
  cin >> n;

  vector<int> v(n);
  for (auto &x : v) cin >> x;
  sort(v.begin(), v.end());

  if (accumulate(v.begin(), v.begin() + n - 1, 0) > v[n - 1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				System.out.println(i+"x"+j+"="+i*j);
			}
		}

	}

}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int32_t main() 
{
    fast;
	int a, b;
	cin >> a >> b;
	cout << a*b;
}




Measured memory_bytes: 3608
// D - Moving Piece
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

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

	int N, K; cin>>N>>K;
	vi P(N); rep(i, N) cin>>P[i], P[i]--;
	vi C(N); rep(i, N) cin>>C[i];

	ll INF = 1e18;
	ll score = -INF;
	rep(st, N){
		ll lap_sc = 0;
		int lap_cn = 0;
		int nx = st;
		while(true){
			lap_cn++;
			lap_sc += C[nx];
			if(st == (nx = P[nx])) break;
		}
		lap_sc = max(0LL, lap_sc);

		ll sum_sc = 0;
		for(int k_cn=1; k_cn<=K; k_cn++){
			sum_sc += C[nx];
			score = max(score, sum_sc + lap_sc * ((K - k_cn) / lap_cn));
			if(st == (nx = P[nx])) break;
		}
	}
	cout<< score <<endl;
}


Measured memory_bytes: 3712
#include<stdio.h>
int main(void){
  int n ,x ,i ,min = 1000 ,count = 0;
  scanf("%d %d",&n ,&x);

  int m[n];
  for(i = 0; i < n; i++){
    scanf("%d",&m[i]);
    min = (min < m[i]) ? min : m[i];
    x -= m[i];
    count ++;
  }
  while(x > 0){
    x -= min;
    if(x >= 0){
      count ++;
    }
  }
  printf("%d",count);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n, a, b, ans;
	cin >> n >> a >> b;
	if (n == 1) {
		if (a == b) {
			cout << "1" << endl;
		}
		else {
			cout << "0" << endl;
		}
	}
	else if (a == b) {
		cout << "1" << endl;
	}
	else if (b < a) {
		cout << "0" << endl;
	}
	else {
		cout << b * (n - 2) - a * (n - 2) + 1 << endl;
	}
	return 0;
}

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

int main(){
  int num,tmp,count;
  count=0;
  cin>>num;
  vector<int> v;
  for(int i=0;i<num;i++){
  	cin>>tmp;
  	v.push_back(tmp);
  }
  for(int i=0; i<num-2;i++){
  	if(v.at(i)<v.at(i+1)&&v.at(i+1)<v.at(i+2)){
  	  count++;
  	}else if(v.at(i)>v.at(i+1)&&v.at(i+1)>v.at(i+2)){
      count++;
  	}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_114
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int all = (int)Math.Pow(4, 9);
            int cnt = 0;
            for(int i = 0; i < all; i++)
            {
                int val = 0;
                int ii = i;
                bool[] ok = new bool[4];
                for(int j = 0; j < 9; j++)
                {
                    if (ii == 0) break;
                    int k = ii % 4;
                    if (k > 0)
                    {
                        val += (k * 2 + 1) * ((int)Math.Pow(10, j));
                    }
                    ii /= 4;
                    ok[k] = true;
                }
                if (!ok[0] && ok[1] && ok[2] && ok[3] && val <= n)
                {
                    cnt++;
                }
                //Console.WriteLine(val);
            }
            Console.WriteLine(cnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 15180
N, K = map(int, input().split())
S = str(input())
if S[K-1] == "A":
  S = S[:K-1] + "a" + S[K:]
elif S[K-1] == "B":
  S = S[:K-1] + "b" + S[K:]
else :
  S = S[:K-1] + "c" + S[K:]
print(S)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mod 1e9+7

int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
      int  n,ans=INT_MAX;
      cin>>n;
      vector<int>v(n);
      for(int i=0; i<n; i++){
	    cin>>v[i];
	 }
	  for(int i=1; i<100; i++){
	     int sum=0;
	   for(int j=0; j<n; j++){
		  // cout<<ans<<"  ";
	     
	     sum+= ((v[j]-i)*(v[j]-i)) ;
	     
	   }
	   ans =min(ans,sum);
	  }
	  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#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;


int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N){
      cin>>A.at(i);
  }
  bool judge=true;
  rep(i,N){
      if(A.at(i)%2==0){
          if(A.at(i)%3!=0 && A.at(i)%5!=0){
              judge=false;
          }
      }
  }
  if(judge){cout<<"APPROVED"<<endl;}
  else{cout<<"DENIED"<<endl;}
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int h1,h2,m1,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    m1+=60*h1;
    m2+=60*h2;
    printf("%d\n",m2-m1-k);
    return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sigma_size 30
#define max_size (int)(1e5+10)
#define MAX (int)(1e5+7)
int qread()
{
	char c; int s=0,t=1; while ((c=getchar())<'0' || c>'9') (c=='-' && (t=-1));
	do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*t;
}

struct node{
	int val;
	int NO;
}stu[max_size];
bool operator < ( node a , node b )
{
	return a.val < b.val;
}
int main ()
{
	int n = qread();
	for ( int i = 1 ; i <= n ; i++ )
	{
		int x = qread();
		stu[i].val = x;
		stu[i].NO = i;
	}
	sort ( stu+1 , stu+1+n );
	for ( int i = 1 ; i <= n ; i++ )
	{
		cout << stu[i].NO;
		if ( i < n )
			cout << " ";
		else cout << endl;
	}
}

Measured memory_bytes: 4372
n,x,m=map(int,input().split())
s=x
t={x}
u=[x]
for i in range(1,n):
    x=pow(x,2,m)
    if x==0:break
    if x==1:
        s+=n-i
        break
    if x in t:
        j=u.index(x)
        s=sum(u[:j])
        u=u[j:]
        s+=(n-j)//len(u)*sum(u)
        s+=sum(u[:(n-j)%len(u)])
        break
    s+=x
    t|={x}
    u+=x,
print(s)

Measured memory_bytes: 73480
#include<bits/stdc++.h>
#define ll long long
#define  vi vector<int>
#define pb push_back
//#define int long long
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define pi pair<int,int>
#define F first
#define S second
using namespace std;

//int mod=(int)(1e9+7);

void solve()
{
 double n;cin>>n;
 cout<<2LL*3.14*n;

}

signed main()
{ boost;
 //cout<<fixed<<setprecision(14 );
 // int t;cin>>t;
  //for(int i=1;i<=t;i++)
  solve();
 // cout<<"Case #"<<i<<": "<<solve()<<endl;

return 0;
}

Measured memory_bytes: 3712
S, C = map(int, input().split())

ans = 0

#Sとccだけで作る(SとCが足りている)
if S <= C//2:
    ans += S
    C -= S*2

    if C > 0:
        # 残りのCでSccを作る
        ans += C//4
else:
    ans += (C//2)
        
print(ans)

Measured memory_bytes: 2940
def poll(arr):
    ans_h = {}
    for ele in arr:
        if ele in ans_h.keys():
            ans_h[ele] += 1
        else:
            ans_h[ele] = 0
    max_v = max(ans_h.values())
    mkv = [kv for kv in ans_h.items() if kv[1] == max_v]
    for ele in sorted(mkv):
        print(ele[0])

if __name__ == "__main__":
    n = int(input())
    arr = [input() for _ in range(0, n)]
    poll(arr)

Measured memory_bytes: 47744
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int num[] = new int[3];
        //String s = stdIn.next();
        //char c[] = s.toCharArray();
        //boolean flag = true;
        
        if(a <= 8 && b <= 8){
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
        
        
        
        //System.out.println();
        //System.out.print();
    }
}


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

int main() {
  int n; cin >> n;
  vector<int> sort_x(n), x(n);
  rep(i,n) {
    int a;
    cin >> a;
    x[i] = a;
    sort_x[i] = a;
  }
  sort(sort_x.begin(), sort_x.end());
  int med = n/2;
  int median_big = sort_x[med];
  int median_small = sort_x[med-1];

  rep(i,n) {
    if (x[i] >= median_big) cout << median_small << endl;
    else cout << median_big << endl;
  }
  return 0;
}

Measured memory_bytes: 4840
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())


n,s=sep()
ar=lis()
ar.insert(0,0)
dp=[[0]*(s+2) for _ in range(n+2)]
dp[0][0]=1
N=998244353
for i in range(1,n+1):
    for j in range(0,s+1):
        dp[i][j]=(2*dp[i-1][j])%N
        if j-ar[i]>=0:
            dp[i][j]=(dp[i][j]+dp[i-1][j-ar[i]])%N
#print(dp)
print(dp[n][s])



Measured memory_bytes: 135460
r,c=map(int,input().split())
a=[]
for i in range(r):
    a+=[list(map(int,input().split()))]
    a[i].append(sum(a[i]))
for i in range(len(a)):
    print(" ".join(list(map(str,a[i]))))
b=[]
t=[]
d=0
for i in range(c+1):
    for j in range(r):
        b+=[a[j][i]]
    t+=[sum(b)] 
    b=[]
print(" ".join(list(map(str,t))))
    
    
    

Measured memory_bytes: 7736
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pint pair<int,int>
typedef long long lint;

int main(void){
    int N,K;
    scanf("%d%d",&N,&K);
    int A[N];
    rep(i,N) scanf("%d",&A[i]);
    rep(i,N) A[i]--;
    pint Sum[N+1]={};
    Sum[0].first=0,Sum[0].second=0;
    rep(i,N){
        Sum[i+1].first=(Sum[i].first+A[i])%K;
        Sum[i+1].second=i+1;
    }
    lint ans=0;
    sort(Sum,Sum+N+1);
    int num=Sum[0].first,count=0;
    int las=0,top=1;
    int begsave=0;
    for(int i=0;i<=N;i++){
        if(Sum[i].first==num) count++,top=Sum[i].second;
        else{
            count=1,num=Sum[i].first;las=Sum[i].second;
            begsave=i;
            continue;
        }
        if(top-las>=K){
            while(top-las>=K){
                count--;
                begsave++;
                las=Sum[begsave].second;
            }
        }
        ans+=count-1;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 6100
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int m[510][510][2];
char s[510][510];

int main() {
	int h,w;
	while(h=in(),w=in()){
		int i;
		for(i=0;i<h;i++){
			scanf("%s",s[i]);
		}
		int mx=0;
		memset(m,0,sizeof(m));
		if(s[0][0]=='.')m[0][0][0]=1;
		else m[0][0][0]=0;
		chmax(mx,m[0][0][0]);
		for(i=1;i<w;i++){
			if(s[0][i]=='.')m[i][0][0]=m[i-1][0][0]+1;
			else m[i][0][0]=0;
			chmax(mx,m[i][0][0]);
		}
		int j,k;
		for(i=1;i<h;i++){
			if(s[i][0]=='.')m[0][0][1]=1;
			else m[0][0][1]=0;
			for(j=1;j<w;j++){
				if(s[i][j]=='.'){
					m[j][0][1]=m[j-1][0][1]+1;
					for(k=1;k<h&&k<w;k++){
						m[j][k][1]=min(m[j][0][1],m[j][k-1][0]);
						if(m[j][k][1]==0)break;
					}
				}
				else m[j][0][1]=0;
				for(k=0;k<h&&k<w;k++){
					m[j][k][0]=m[j][k][1];
					if(m[j][k][0]==0)break;
					chmax(mx,m[j][k][0]*(k+1));
				}
			}
		}
		cout<<mx<<endl;
	}
	return 0;
}

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

namespace my {
/*汎用*/
template <typename T>
void input_vec(vector<T> &a, ll n) {
  assert(a.empty());
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  assert(a.empty());
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}

char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }

/*整数*/
ll gcd(ll a, ll b) {  // O( log(max(a,b)) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(max(a,b)) )
ll modinv(ll n, ll mod) {                               // O( log(max(n,mod)) )
  assert(mod > 0 && my::gcd(n, mod) == 1);
  n %= mod;
  if (n < 0) n += mod;
  ll a = mod, b = n, x = 1, y = 0;
  while (b != 0) {
    ll q = a / b, r = a % b;
    a = b;
    b = r;
    y -= q * x;
    swap(x, y);
  }
  y %= mod;
  if (y < 0) y += mod;
  return y;
}

bool is_prime(ll n) {  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> prime_factorize(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}

/*union find*/
class unionfind {
 private:
  /*根のparの値は「-(その木の要素数)」とする*/
  ll n_;
  vector<ll> par;

  ll root(ll a) {  // O( log(n) )
    if (par.at(a) < 0)
      return a;
    else {
      par.at(a) = root(par.at(a));  //経路圧縮
      return par.at(a);
    }
  }

 public:
  unionfind(ll n) : n_(n), par(n, -1) {}  // O(n)

  void unite(ll a, ll b) {  // O( log(n) )
    assert(0 <= a && a < n_);
    assert(0 <= b && b < n_);
    if (root(a) == root(b))
      return;
    else {
      ll ra = root(a), rb = root(b);
      if (-par.at(ra) < -par.at(rb)) swap(ra, rb);  //サイズによる併合
      par.at(ra) += par.at(rb);
      par.at(rb) = ra;
    }
  }

  bool is_same(ll a, ll b) {  // O( log(n) )
    assert(0 <= a && a < n_);
    assert(0 <= b && b < n_);
    return root(a) == root(b);
  }

  ll size(ll a) {  // O( log(n) )
    assert(0 <= a && a < n_);
    return -par.at(root(a));
  }
};
}  // namespace my
////////////////////////////////////////////////

int main() {
  string s;
  cin >> s;
  if (s.back() != 's')
    s.push_back('s');
  else
    s += "es";
  cout << s << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define MOD 1000000007

int main(){
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> T, A;
  rep(i,N){
    int a;
    cin >> a;
    T.push_back(a);
  }
  rep(i,N){
    int a;
    cin >> a;
    A.push_back(a);
  }

  vector<int> v1(N, -1);
  vector<int> v2(N, -1);

  int p = -1;
  rep(i,T.size()){
    if(T[i] > p){
      v1[i] = T[i];
      p = T[i];
    }
  }
  p = -1;
  for(int i=N-1; i>=0; i--){
    if(A[i] > p){
      v2[i] = A[i];
      p = A[i];
    }
  }

  vector<int> v(N, -1);
  rep(i,N){
    if(v1[i] < 0 && v2[i] < 0){
      v[i] = -1;
    }
    else if(v1[i] < 0 && v2[i] >= 0){
      v[i] = v2[i];
    }
    else if(v1[i] >= 0 && v2[i] < 0){
      v[i] = v1[i];
    }
    else{
      if(v1[i] == v2[i]){
        v[i] = v1[i];
      }else{
        cout << 0 << endl;
        return 0;
      }
    }
  }

  ll ret = 1;
  rep(i,N){
    if(v[i] == -1){
      ll a = min(T[i], A[i]);
      ret *= a;
      ret %= MOD;
    }else{
      if(T[i] >= v[i] && A[i] >= v[i]){
        ;
      }else{
        ret = 0;
      }
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 2296
#include <stdio.h>
int main(){
  int sA, ii;
  scanf("%d", &sA);
  int A[sA];
  for(ii=0;ii<sA;ii++)scanf("%d", &A[ii]);
  int sm, jj;
  scanf("%d", &sm);
  int M[sm];
  for(jj=0;jj<sm;jj++)scanf("%d", &M[jj]);
  int ANS[9999];
  int n;
  int sum;
  unsigned long long int max;
  unsigned long long int i;
  int j,k, l, count;

  sA = (sizeof A/sizeof A[0]);

  for(n=0; n<sA; n++){
    ANS[n] = A[n];
  }
  max = 1 << sA;
  for(i=1; i<max; i++){
    sum = 0;
    for(j=0; j<sA; j++){
      if( i & 1<<j ){
        sum += A[j];
      }
    }
    ANS[n] = sum;
    for(k=0; ANS[k]!=sum; k++){};
    if( k==n ){
      n++;
    }
  }

  for(l=0;l<sm;l++){
    count=0;
    for(k=0; k<n; k++){
      if(M[l]==ANS[k])count=1;
    }
    if(count==1) printf("yes\n");
    if(count==0) printf("no\n");
  }
}


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

	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		int[][]ar=new int[n][3], dp=new int[n][3];
		StringTokenizer st;
		for(int i=0;i<n;i++){
			st=new StringTokenizer(br.readLine());
			for(int j=0;j<3;j++){
				ar[i][j]=Integer.parseInt(st.nextToken());
				dp[i][j]=Integer.MIN_VALUE;
			}
		}
		for(int i=0;i<3;i++)dp[0][i]=ar[0][i];
		for(int i=1;i<n;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					if(k==j)continue;
					dp[i][j]=Math.max(dp[i][j], dp[i-1][k]+ar[i][j]);
				}
			}
		}
		int max=Integer.MIN_VALUE;
		for(int i=0;i<3;i++)max=Math.max(max, dp[n-1][i]);
		System.out.println(max);
	}

}


Measured memory_bytes: 51656
#include <stdio.h>
int main(){
  unsigned long long lnew=1, l1=2, l2=1;
  int n;
  scanf("%d",&n);
  for(int i=2; i<=n; i++){
    l2 = l1;
    l1 = lnew;
    lnew = l1 + l2;
  }
  printf("%llu",lnew);
  return 0;
}

Measured memory_bytes: 128
import itertools
import math

LIM = 50



def do():
    ans = 0
    A,B,C,D,E,F= list(map(int,input().split(" ")))
    waters = []
    for i in range(31):
        for j in range(31):
            water = A*i* 100+B*j* 100
            if water <= F and water != 0:
                waters.append(water)
    solts = []
    for i in range(3000):
        for j in range(3000):
            solt = C * i + D * j
            if solt > E * F /100:
                break
            solts.append(solt)

    max_nodo = -1
    ans_water = 0
    ans_solt = 0
    for solt in solts:
        for water in waters:
            if solt/(water/100) <= E:
                if (100 * solt)/(solt+water) >= max_nodo and water + solt <= F:
                    max_nodo =(100 * solt)/(solt+water)
                    ans_water = water + solt
                    ans_solt = solt

    print(ans_water,ans_solt)





if __name__ == "__main__":
    do()

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

int main() {
  long long int N,T,cnt=0,prev_t=0;
  cin>>N>>T;
  for(int i=0;i<N;i++){
    long long int t;
    cin>>t;
    if(i==N-1){cnt+=T;};
    if(i==0){continue;}
    else if(prev_t+T>t){cnt+=t-prev_t;}
    else{cnt+=T;}
    prev_t=t;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
import           Data.IORef
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           System.IO

main :: IO ()
main = flipflip

flipflip :: IO ()
flipflip = do
  nmT <- T.getLine
  let [nT, mT] = T.split (== ' ') nmT
      n = read $ T.unpack nT :: Int
      m = read $ T.unpack mT :: Int
      nm = n * m
      ans' = case nm of
              1 -> 1
              2 -> 1
              _ -> (n - 2) * (m - 2)
      ans
        | ans' < 0  = negate ans'
        | otherwise = ans'
  print ans

Measured memory_bytes: 508
N, X = map(int, input().split())
xs = list(map(int, input().split()))

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

ans = abs(xs[0] - X)
for x in xs[1:]:
    ans = gcd(ans, abs(x - X))

print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int mx = 1e18;

int32_t main(){_
   
   cin>>n;

   for (int i = 0; i < n; ++i)
   {
      cin >> a[i];
      if (a[i] == 0){
         cout<<0;
         exit(0);
      }
   }

   int pro = 1;
   for (int i = 0; i < n; ++i)
   {
      int x = a[i];
      if (pro > mx / x){
         cout<<-1;
         exit(0);
      }
      pro *= x;
   }
   
   cout<<pro;

   return 0;
}

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

int main()
{
  int n, k;
  int s[101];

  while (cin >> n >> k, n + k){
    bool judge = true;
    for (int i = 0; i < k; i++) cin >> s[i];
    int b;
    for (int i = 0; i < n; i++){
      for (int j = 0; j < k; j++){
        cin >> b;
        s[j] -= b;
      }
    }

    for (int i = 0; i < k; i++){
      if (s[i] < 0) judge = false;
    }

    if (judge)  cout << "Yes\n";
    else  cout << "No\n";
  }
}

Measured memory_bytes: 1120
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb emplace_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
const int mod=1e9+7;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
ll binpow(ll a, ll b, ll m) 
{a %= m;b%=(m-1);ll res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1; }return res;}
void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,temp,x,y;
string str;
void solveforthiscase(const int & test)
{//deb(test);
set<ll> s;
for(int i=0;i<3;i++)
{
    cin>>a;
    s.insert(a);
}
if(s.size()==2)
{
    cout<<"Yes";
}
else
cout<<"No";






return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    int count=0;
    for(int i=1;i<=N;i++){
        if(1<=i&&i<=9)count++;
        if(100<=i&&i<=999)count++;
        if(10000<=i&&i<=99999)count++;
    }
    cout<<count<<endl;
}

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

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;

using namespace std;

void init()
{
}

const int N = 111111;
ll a[N];

void solve()
{
	int n;
	cin >> n;
	rep(i, n)
	{
		cin >> a[i];
	}

	rep(i, n)
	{
		if (a[i] == 0)
		{
			cout << 0 << endl;
			return;
		}
	}

	ll maxi = (ll)1000000000 * (ll)1000000000;

	ll cur = 1;
	rep(i, n)
	{
		ll b = (maxi - 1) / cur + 1;

		if (b < a[i])
		{
			cout << -1 << endl;
			return;
		}

		cur *= a[i];

		if (cur > maxi)
		{
			cout << -1 << endl;
			return;
		}
	}

	cout << cur << endl;
}

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


Measured memory_bytes: 3972
#include <stdio.h>

#define true 1
#define false 0

int solve(int *, int, int, int);

int main() {
  int i, j, n, q, flag = 0;
  int dataa[2000], datam[2000];

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

  for (i = 0; i < q; i++) {
    flag = solve(dataa, 0, datam[i], n);
    if (flag == true) {
      printf("yes\n");
    }
    else if (flag == false) {
      printf("no\n");
    }
  }
  
  return 0;
}


int solve(int *data, int i, int m, int n) {
  int res1, res2;
  
  if (m == 0) return true;

  else if (i >= n) return false;

  res1 = solve(data, i+1, m, n);
  res2 = solve(data, i+1, m-data[i], n);

  if (res1 == false && res2 == false) return false;
  else return true;
}



Measured memory_bytes: 2048
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000 + 50;
const int mod = 1e9 + 7;
int n,k;
int h[N];
ll dp[N][N];
int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    ios::sync_with_stdio(false);
//    cin.tie(NULL);
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i)
        scanf("%d", h + i);
    if (n == k)
    {
        puts("0");
        return 0;
    }
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i)
        for (int l = 1; l <= n - k; ++l)
            for (int j = 0; j < i; ++j)
                dp[i][l] = min(dp[i][l], dp[j][l - 1] + max(0, h[i] - h[j]));
    ll ans = 1e18;
    for (int i = 1; i <= n; ++i)
        ans = min(ans, dp[i][n - k]);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 72960
k = gets.to_s.to_i
a,b = gets.to_s.split.map{|t|t.to_i}
# m = Array.new(n){ gets.to_s.split.map{|t|t.to_i} }
# s = gets.to_s.chomp

a.upto(b) do |i|
  if i % k == 0
    puts "OK"
    exit
  end
end

puts "NG"

Measured memory_bytes: 14384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;


void solve()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (int i = 0; i < M; ++i)
	{
		cin >> X[i];
	}
	if (N >= M)
	{
		cout << 0 << endl;
		return;
	}
	sort(X.begin(), X.end());
	vector<int> dist(M - 1);
	for (int i = 0; i < M - 1; ++i)
	{
		dist[i] = X[i + 1] - X[i];
	}
	sort(dist.begin(), dist.end());
	long long int ans = 0;
	for (int i = 0; i < dist.size() - (N - 1); ++i)
	{
		ans += dist[i];
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1024
/* 
   AOJ 2006
   Keitai Message
   2015.4.25
 */

#include<stdio.h>

char one[6] = {'.', ',', '!', '?', ' ', '\0'};
char two[4] = {'a', 'b', 'c', '\0'};
char three[4] = {'d', 'e', 'f', '\0'};
char four[4] = {'g', 'h', 'i', '\0'};
char five[4] = {'j', 'k', 'l', '\0'};
char six[4] = {'m', 'n', 'o', '\0'};
char sevene[5] = {'p', 'q', 'r', 's', '\0'};
char eight[4] = {'t', 'u', 'v', '\0'};
char nine[5] = {'w', 'x', 'y', 'z', '\0'};

 
void message_analizer(char* input_str){
  char message[76];
  int i = 0, endpoint = 0, continuity_counter = 0, zero_counter = 0;
  while(input_str[i] != '\0'){
    switch(input_str[i]){
    case '0':
      zero_counter++;
      if(i == 0 || zero_counter > 1){
	break;
      }
      endpoint++;
      continuity_counter = 0;
      zero_counter = 1;
      break;
    case '1':
      message[endpoint] = one[continuity_counter % 5];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '2':
      message[endpoint] = two[continuity_counter % 3];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '3':
      message[endpoint] = three[continuity_counter % 3];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '4':
      message[endpoint] = four[continuity_counter % 3];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '5':
      message[endpoint] = five[continuity_counter % 3];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '6':
      message[endpoint] = six[continuity_counter % 3];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '7':
      message[endpoint] = sevene[continuity_counter % 4];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '8':
      message[endpoint] = eight[continuity_counter % 3];
      continuity_counter++;
      zero_counter = 0;
      break;
    case '9':
      message[endpoint] = nine[continuity_counter % 4];
      continuity_counter++;
      zero_counter = 0;
      break;
    }
    i++;
  }
  message[endpoint] = '\0';
  printf("%s\n", message);
  return ;
}

int main(void){
  int num, i;
  char input_str[1024];

  scanf("%d", &num);
  for(i = 0; i < num; i++){
    scanf("%s", input_str);
    message_analizer(input_str);
  }
  
  return 0;
}

Measured memory_bytes: 588
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String a = sc.next();
      if(a.contains("B")){
        System.out.println(a.replace("B","R"));
      }else if(a.contains("R")){
        System.out.println(a.replace("R","B"));
      }
    }
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

bool check[401][401] = { };

int main(){
	int h, w;
	cin >> h >> w;
	string s[h];
	REP(i, h) cin >> s[i];
	ll ans = 0;
	queue<P> que;
	REP(i, h){
		REP(j, w){
			if(!check[i][j]){
				que.push({i, j});
				ll wh = 0, b = 0;
				if(s[i][j] == '#') b++;
				else wh++;
				check[i][j] = true;
				while(!que.empty()){
					P cur = que.front(); 
					que.pop();
					int dx[4] = {0, 0, 1, -1};
					int dy[4] = {1, -1, 0, 0};
					REP(k, 4){
						int x = cur.first + dx[k];
						int y = cur.second + dy[k];
						if((0 <= x) && (x < h) && (0 <= y) && (y < w) && (s[cur.first][cur.second] != s[x][y]) && (!check[x][y])){
							check[x][y] = true;
							que.push({x, y});
							if(s[x][y] == '#') b++;
							else wh++;
						}
					}
				}
				ans += wh*b;
			}
		}
	}
	cout << ans << endl;
	return 0;
} 

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

#define MOD 998244353

vector< vector<int> > A;

long long power(long long N, long long expo)
{
    long long ans = 1;
    
    while(expo)
    {
        if(expo % 2)
            ans = ans * N % MOD;
        
        N = N * N % MOD;
        expo /= 2;
    }
    
    return ans;
}

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

    int N, M;
    cin >> N >> M;
    
    for(int i=0; i<N; i++)
    {
        vector<int> B(M, 0);
        A.push_back(B);
        
        for(int j=0; j<M; j++)
        {
            int x;
            cin >> x;
            
            A[i][j] = x;
        }
    }
    
    long long ans = power(2, N) + MOD - 1;
    
    for(int i=0; i<N; i++)
    {
        int f = -1;
        sort(A.begin()+i, A.end(), greater< vector<int> >());
        
        for(int j=0; j<M; j++)
        {
            if(A[i][j] == 1)
            {
                f = j;
                break;
            }
        }
        
        if(f == -1)
        {
            ans += MOD - power(2, N-i) + 1;
            break;
        }
        
        for(int j=i+1; j<N; j++)
        {
            if(A[j][f] == 1)
            {
                for(int k=f; k<M; k++)
                    A[j][k] ^= A[i][k];
            }
        }
    }
    
    cout << ans % MOD * power(2, M-1) % MOD << "\n";
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

template<class T>
struct Graph {
    struct Edge {
        int dst; T w;
        Edge() {};
        Edge(int _d, T _w) : dst(_d), w(_w) {}
    };

    const T INF = std::numeric_limits<T>::max();
    const int n;
    int s, t;
    std::vector<std::vector<Edge>> adj;
    std::vector<T> dist;

    Graph(int _n, int _s, int _t = -1)
        : n(_n), s(_s), t(_t), adj(n), dist(n, INF) { }

    void add_arc(int u, int v, T w) { adj[u].emplace_back(Edge(v, w)); }
    T distance(const int _t) const { return dist[_t]; }
    void ChangeSource(const int _s) {
        s = _s; std::fill(dist.begin(), dist.end(), INF); Dijkstra();
    }

    void Dijkstra() {
        using State = std::pair<T, int>;
        std::priority_queue<State, std::vector<State>, std::greater<State>> que;

        que.emplace(0, s);
        dist[s] = 0;

        while (!que.empty()) {
            T d; int v;
            std::tie(d, v) = que.top(); que.pop();

            if (dist[v] < d) continue;
            // if (v == t) return ;
            for (const auto &e : adj[v]) {
                if (d + e.w < dist[e.dst]) {
                    dist[e.dst] = d + e.w;
                    que.emplace(dist[e.dst], e.dst);
                }
            }
        }
    }
};

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

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

    vector<pair<int, int>> e(m);
    for (int i = 0; i < m; ++i) {
        cin >> e[i].first >> e[i].second;
        --e[i].first; --e[i].second;
    }

    int s, t;
    cin >> s >> t;
    --s; --t;

    Graph<int> g(3 * n, 3 * s);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < 3; ++j) {
            g.add_arc(3 * e[i].first + j, 3 * e[i].second + ((j + 1) % 3), 1);
        }
    }

    g.Dijkstra();
    if (g.distance(3 * t) < g.INF) cout << g.distance(3 * t) / 3 << '\n';
    else cout << "-1\n";

    return 0;
}


Measured memory_bytes: 18688
#include <cstdio>
#include <cstring>

const int MaxN = 10, MaxM = 1000;

int N, M, K;
int A[MaxN + 5][MaxM + 5];

inline int getDigit() {
  char c;
  do c = getchar(); while (c < '0' || c > '9');
  return c - '0';
}

void init() {
  scanf("%d %d %d", &N, &M, &K);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j)
      A[i][j] = getDigit();
}

void solve() {
  int ans = N * M;
  for (int s = 0; s < (1 << (N - 1)); ++s) {
    int n = 1, cnt = __builtin_popcount(s);
    static int a[MaxN + 5][MaxM + 5], sum[MaxN + 5];
    memset(a, 0, sizeof a);
    memset(sum, 0, sizeof sum);
    bool valid = true;
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= M; ++j) a[n][j] += A[i][j];
      if (s & (1 << (i - 1))) n++;
    }
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= M; ++j)
        if (a[i][j] > K) valid = false;
    if (valid == false) continue;
    for (int j = 1; j <= M; ++j) {
      bool ok = true;
      for (int i = 1; i <= n; ++i)
        if (sum[i] + a[i][j] > K) ok = false;
      if (ok == false) {
        cnt++;
        for (int i = 1; i <= n; ++i) sum[i] = a[i][j];
      } else for (int i = 1; i <= n; ++i) sum[i] += a[i][j];
    }
    if (cnt < ans) ans = cnt;
  }
  printf("%d\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for (ll &e : A) {
    cin >> e;
    sum += e;
  }
  
  ll s = 0;
  ll v = sum;
  for (int i = 0; i < N; i++) {
    ll delt;
    s += A[i];
    delt = max(s*2 - sum, sum - s*2);
    v = min(delt, v);
  }
  
  cout << v << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
vector<int>v;
int n,x,i;
int main(){
  cin>>n;
  for(i=0;++i<=n;){
    cin>>x;
    if(x>i) return 0*puts("-1");
    v.insert(v.begin()+x-1,x);
  }
  for(i=-1;++i<n;)cout<<v[i]<<endl;
}


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

int n;
const int INF = 1000000;
vector<vector<int> > v, c;
vector<int> w;

void trip(int id, int dp) {
	if (dp > n)
		return;

	for (int j = 0; j < (int)v[id].size(); j++) {
		if (w[v[id][j]] > w[id] + c[id][j]) {
			w[v[id][j]] = w[id] + c[id][j];
			trip(v[id][j], dp + 1);
		}
	}
}

int main()
{
	cin >> n;

	int u, k, v1, c1;
	v.resize(n);
	c.resize(n);
	w.assign(n, INF);

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v1 >> c1;
			v[u].push_back(v1);
			c[u].push_back(c1);
		}
	}

	w[0] = 0;
	trip(0, 1);

	for (int i = 0; i < n; i++)
		cout << i << " " << w[i] << endl;

	return 0;
}


Measured memory_bytes: 3168
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b>> c;
	cout << (b-a == c-b ? "YES" : "NO") << endl;
	
	return 0;
}

Measured memory_bytes: 764
n=int(input())
a=list(map(int,input().split()))
ans=0
r,l=0,0
s,x=0,0
while l<n:
  while r<n and s+a[r]==x^a[r]:
    s+=a[r]
    x^=a[r]
    r+=1
  ans+=r-l
  s-=a[l]
  x^=a[l]
  if r==l:r+=1
  l+=1
print(ans)

Measured memory_bytes: 100600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX = 510000;
const ll mod = 1e9+7;

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

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * (ll)i % mod;
    inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
  ll n, k;
  cin >> n >> k;
  COMinit();
  if(n > k) cout << 0 << endl;
  else {
    ll ans = 1;
    for(ll i = 1; i <= n; i++) ans = ans * i % mod;
    ans = ans * COM(k,n) % mod;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 15040
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::Ordering;
use std::collections::BinaryHeap;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn divisor_pairs(n: i64) -> Vec<(i64, i64)> {
    let mut v = Vec::new();
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            v.push((i, n / i));
        }
        i += 1;
    }

    v
}

fn main() {
    input! {
        n: i64
    }

    let d = divisor_pairs(n);
    let f = |x| (x as f64).log10() as i64 + 1;
    let ans = d
        .into_iter()
        .map(|(a, b)| std::cmp::max(f(a), f(b)))
        .min()
        .unwrap();
    println!("{}", ans);
}


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

using namespace std;

int main(void){
  while(true){
    int n;
    scanf("%d", &n);
    if(n == 0){
      return 0;
    }
    int sum = 0;
    int doubled_sum = 0;
    for(int i = 0;i < n;++i){
      int x;
      scanf("%d", &x);
      sum += x;
      doubled_sum += x * x;
    }
    double avg = (double) sum / n;
    double doubled_avg = (double) doubled_sum / n;
    printf("%lf\n", sqrt(doubled_avg - (avg*avg)));
  }
}



Measured memory_bytes: 3224