akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
   ll n,i;
   cin>>n;
   ll arr[n];
   for(i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   unordered_map<ll,ll>mp;
   for(i=0;i<n;i++)
   {
       mp[arr[i]-1]++;
       mp[arr[i]+1]++;
       mp[arr[i]]++;
   }
   ll mx=-1;
   ll mxe;
   for(auto it=mp.begin(); it!=mp.end(); it++)
   {
       if(it->second>mx)
       {
           mx=it->second;
           mxe=it->first;
       }
   }
   ll ans=0;
   for(i=0;i<n;i++)
   {
       if(arr[i]==mxe || arr[i]-1==mxe || arr[i]+1==mxe)
       {
           ans++;
       }
   }
   cout<<ans<<endl;
}


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

int main(){
    int K, A, B, c=0;
    string ans;
    cin >> K;
    cin >> A >> B;
    ans = "NG";

    while(1){
        c++;
        if((A<=c*K)&&(c*K<=B)){
            ans = "OK";
            break;
        }
        if(c*K>B){
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int x;
	cin >> x;
	int sum = 1;
	int sum2 = 1;
	for (int i = 0; i < 9; i++) {
		sum = sum * 2;
		sum2 = sum2 * 3;
		if (sum == x || sum2 == x) {
			cout << x << endl;
			return 0;
		}
	}
	
	int max = -1000000;
	for (int i = 1; i <= 31; i++) {
		if (i * i <= x && i * i > max) {
			max = i * i;
		}
	}
	int big = -1000000;
	for (int j = 1; j <= 10; j++) {
		if (j * j * j <= x && j * j * j > big) {
			big = j * j * j;
		}
	}
	int dai = -1000000;
	for (int k = 1; k <= 5; k++) {
		if (k * k * k * k <= x && k * k * k * k > dai) {
			dai = k * k * k * k;
		}
	}

	
	if (max > big&&max>dai) {
		cout << max << endl;
		return 0;
	}

	if (dai > max&& dai > big) {
		cout << dai << endl;
		return 0;
	}
	cout <<big<< endl;
	return 0;
	
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
   input!{a:[i64;3]};
   println!("{}", if a[2] >= a[0] && a[2] <= a[1] {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def dfs(v, x, g, used, ans):
    used[v] = True
    res = x[v]
    for e in g[v]:
        if used[e[0]]:
            continue
        r = dfs(e[0], x, g, used, ans)
        if r:
            ans.append(e[1])
        res ^= r
    return res


def main():
    n, m = map(int, input().split())
    ab = [[] for _ in range(n)]
    ans = []
    g = [[] for _ in range(n+1)]
    used = [False] * (n+1)

    for i in range(n):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[0])
    al = list(map(lambda x: x[0], ab))
    for i in range(m):
        l, r = map(int, input().split())
        l = bisect.bisect_left(al, l)
        r = bisect.bisect_right(al, r)
        g[l].append((r, i+1))
        g[r].append((l, i+1))

    x = [0] * (n+1)
    x[0] = ab[0][1]
    for i in range(n-1):
        x[i+1] = ab[i][1] ^ ab[i+1][1]
    x[n] = ab[n-1][1]

    for i in range(n+1):
        if used[i]:
            continue
        if dfs(i, x, g, used, ans):
            print(-1)
            return

    ans.sort()
    print(len(ans))
    print(*ans)


main()


Measured memory_bytes: 149612
N = int(input())
words = [input() for n in range(N)]

def func(N, words):
    if (len(words) != len(set(words))):
        return "No"
    
    for n in range(N-1):
        if words[n][-1] != words[n+1][0]:
            return "No"
    else:
        return "Yes"

print(func(N, words))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<int> a(n);
  rep(i,n)
    std::cin >> a[i];

  int mini = 1000000;
  for(int i = -100; i <= 100; i++) {
    int ans = 0;
    rep(j,n)
      ans += (a[j]-i)*(a[j]-i);
    if(mini > ans)
      mini = ans;
  }


  std::cout << mini << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    double avg;
    int numbers[n];
    for(int i = 0; i < n; i++) {
        cin >> numbers[i];
        avg += numbers[i];
    }
    avg = round(avg/n); 
    int cost = 0;
    for(int i = 0; i < n; i++){
        cost += (numbers[i] - avg) * (numbers[i] - avg);
    }
    cout << cost << "\n";
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; //00右,01下,10左,11上

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

const int mask=(1<<12)-1;
int h,w,k,memo[50][50][4][1<<12];
char fld[50][50];

inline bool Check(int y,int x){
	return 0<=y&&y<h&&0<=x&&x<w&&fld[y][x]!='#';
}

int Max(int y,int x,int c,int bit){
	int &res=memo[y][x][c][bit];
	if(res!=-1) return res;
	if(y==h-1&&x==w-1&&c==0) return res=0;

	bool done=false;
	int py=y,px=x;
	rep(i,0,6){
		py-=dy[(bit>>(i*2))&3];
		px-=dx[(bit>>(i*2))&3];
		if(y==py&&x==px){
			done=true;
			break;
		}
	}
	int gift=0;
	if(!done&&fld[y][x]!='.') gift=fld[y][x]-'0';

	res=-INF;
	rep(i,0,4){
		int ny=y+dy[i],nx=x+dx[i];
		if(!Check(ny,nx)) continue;
		if(i<2){
			res=max(res,Max(ny,nx,c,((bit<<2)&mask)|i)+gift);
		}else if(c>=1){
			res=max(res,Max(ny,nx,c-1,((bit<<2)&mask)|i)+gift);
		}
	}

	return res;
}

void Solve(){
	fill_n((int*)memo,50*50*4*(1<<12),-1);
	cin >> h >> w >> k;
	rep(i,0,h) rep(j,0,w) cin >> fld[i][j];

	cout << Max(0,0,k,0) << endl;
}

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

Measured memory_bytes: 161200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,t,s;
  cin>>a>>b>>c>>d;
  if(a%d==0){
    t=a/d;
  }else{
    t=a/d+1;
  }
  if(c%b==0){
    s=c/b;
  }else{
    s=c/b+1;
  }
  if(t>=s){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <string.h>
#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const vector<int> ms = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const string NA = "$";

vector<int> as;
vector<string> dp;

inline int match_for(int x) {
    return ms[x];
}

int cmp(const string &a, const string &b) {
    if ((int) a.size() != (int) b.size()) {
        return ((int) a.size() > (int) b.size()) ? 1 : -1;
    }
    return strncmp(a.c_str(), b.c_str(), (int) a.size());
}

string solve(const int N, const vector<int> &as) {
    for (int i = 1; i <= N; i++) {
        for (auto a : as) {
            int req_match = match_for(a);
            if (i - req_match >= 0 && dp[i - req_match] != NA) {
                string cand = dp[i - req_match] + to_string(a);
                if (cmp(cand, dp[i]) > 0) {
                    dp[i] = move(cand);
                }
            }
        }
    }
    return dp[N];
}

int main(void) {
    int N, M;
    cin >> N >> M;

    as.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    reverse(as.begin(), as.end());

    dp.resize(N + 1, NA);
    dp[0] = "";

    string ans = solve(N, as);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 32896
#include<stdio.h>

#include <string.h>

int main()
{
    
    char s[100];
    
    scanf("%s",s);
    
  int len = 0;
  len  = strlen(s);
  int i,j;
  for(i=0;i<len;i++){
    if(i % 2 == 0){
	if(s[i] == 'L'){
	printf("No");
      return 0;
    }
    }else{
	if(s[i] == 'R'){
	printf("No");
      return 0;
    }
  }
  }

printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	int n;
	cin>>n;
	vector< vector<int> > d(n,vector<int>(3));
	vector<int> s(n,0);
	
	int p[3][101]={0};
	
	
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
		cin>>d[i][j];
			p[j][d[i][j]]++;
		}
		
	}
	
	for(int j=0;j<3;j++){
		for(int i=0;i<n;i++){
			if(p[j][d[i][j]]==1)
				s[i]+=d[i][j];
		}
	}
	
	for(int i=0;i<n;i++)
		cout<<s[i]<<endl;
		
	

}

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

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

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



struct edge { int to; ll cap; int rev; };

vector<edge> G[101];
bool used[101];
const ll INF = 1e15;
int n;

void add_edge(int from, int to, ll cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

ll dfs(int v,int t,ll f){
  if(v==t) return f;
  used[v] = true;
  REP(i,G[v].size()){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0ll){
      int d = dfs(e.to, t, min(f,e.cap));
      if(d>0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(int s, int t){
  ll flow = 0ll;
  while(true){
    memset(used,0,sizeof(used));
    ll f = dfs(s,t,INF);
    if(f==0) return flow;
    flow += f;
  }
}

int main(){
  ll sum = 0;
  cin >> n;
  REP(i,n){
    int  x;
    cin >> x;
    if(x<0){
      add_edge(0,i+1,-x);
    }else{
      add_edge(i+1,n+1,x);
      sum += x;
    }
  }
  FOR(i,1,n+1){
    for(int j=i;j<=n;j+=i){
      add_edge(i,j,INF);
    }
  }
  ll ans = max_flow(0,n+1);
  cout << sum-ans <<endl;
}

/*
void waru(int i){
  FOR(j,i,n+1){
    if(j%i==0){
      a[j] = 0;
    }
  }
}
int main(){
  cin >> n;
  FOR(i,1,n+1){
    cin >> a[i];
    sum += a[i];
  }
  while(true){
    bool flag = true;
    FOR(i,1,n+1){
    //  cout << a[i] << " ";
    }
    //cout << endl;
    FOR(i,1,n+1){
      cost[i] = 0;
      FOR(j,i,n+1){
        if(j%i) continue;
        cost[i] -= a[j];
      }
      if(cost[i]>0) flag = false;
    }
    if(flag) break;
    ll ma = cost[1];
    int ma_i;
    FOR(i,1,n+1){
      if(ma < cost[i]){
        ma = cost[i];
        ma_i = i;
      }
    }
    sum += ma;
    waru(ma_i);
  }
  cout << sum << endl;
}
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N,M; cin >> N >> M;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<pair<ll, ll>> CB(M);
  for (int i = 0; i < M; i++) cin >> CB[i].second >> CB[i].first;
  
  sort(A.begin(),A.end());
  sort(CB.begin(),CB.end());
  reverse(CB.begin(),CB.end());
  
  int j = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] < CB[j].first) {
      A[i] = CB[j].first;
      CB[j].second--;
    }
    if (CB[j].second == 0) j++;
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) ans += A[i];
  
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N;
vector<char> v;

int main(){
    cin >> N;
    while(N > 0){
        v.push_back('a' + ((N-1)%26));
        N -= (N-1)%26;
        N /= 26;
    }
    for(int i=v.size()-1;i>=0;i--) cout << v[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(void)
{
	int a,b,c;
	int count=0;
	int i;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for(i=a;i<=b;i++)
	{
		if(c%i==0){
			count++;
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];
    int flag=1;
    int m=arr[0];
    for(int i=1;i<n;i++)
    {
       if(arr[i]<m)
       {
           flag++;
           m=arr[i];
       }
    }
    cout<<flag<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;

namespace abc143_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var d = CIn.ReadIntArray(n);

      var ans = 0L;

      for (var i = 0; i < n - 1; i++)
      {
        for (var j = i + 1; j < n; j++)
        {
          ans += d[i] * d[j];
        }
      }

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}

Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inf 0x3f3f3f3f

using namespace std;

int paths[210][210];
int R[210];
int n,m,r;

void floyd()
{
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
               paths[i][j]=min(paths[i][k]+paths[k][j],paths[i][j]);
            }
        }
    }
}

int main()
{
    while(scanf("%d%d%d",&n,&m,&r)==3)
    {
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                if(i==j)paths[i][j]=0;
                else paths[i][j]=inf;
            }
        }
        for(int i=0;i<r;i++)
        {
            scanf("%d",&R[i]);
        }
        int a,b,c;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            if(paths[a][b]>c||paths[b][a]>c)
            {
                paths[a][b]=paths[b][a]=c;
            }
        }
        floyd();
        sort(R,R+r);
        int ans=inf;
        do
        {
            int sum=0;
            for(int i=0;i<r-1;i++)
            {
                sum+=paths[R[i]][R[i+1]];
            }
            ans=min(ans,sum);
        }while(next_permutation(R,R+r));
        printf("%d\n",ans);
    }
    return 0;
}


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

int main() {
	int n;
	string s;
	cin >> n >> s;

	int x = 0;
	int max = 0;
	for (int i = 0; i < n; i ++) {
		if (s.substr(i, 1) == "I") x ++;
		if (s.substr(i, 1) == "D") x --;
		if (x > max) max = x;
	}

	cout << max << endl;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n;
    cin >> n;
    vi a(n,0);
    rep(i,0,n) cin >> a[i];

    int ans = 0,cur = 0;
    rep(i,1,n) {
        if(a[i-1] >= a[i]) ++cur;
        else {
            // dbg(cur);
            ans = max(ans,cur);
            cur = 0;
        }
    }

    ans = max(ans, cur);

    cout << ans << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

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

    cpuTime();
return 0;
}




Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;
typedef long long ll;

int main() {
    int a, b; cin >> a >> b;
    int sum = a + b;
    int sub = a - b;
    int mul = a * b;
    cout << max(sum, max(sub, mul)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

int dfs(int u, vector<vector<int>>& G, vector<vector<int>>& G_w, vector<int> &visit, vector<int> &nagasa)
{

    visit[u] = 1;
    for (int i = 0; i < G[u].size(); i++)
    {

        int v = G[u][i];

        if (visit[v] == 0)
        {

            nagasa[v] = (nagasa[u] + G_w[u][i] % 2) % 2;
            dfs(v, G, G_w, visit, nagasa);
        }
    }

    return 0;
}

int main()
{

    int N;
    cin >> N;
    vector<vector<int>> G(N);

    vector<vector<int>> G_w(N);

    vector<int> nagasa(N, 0);
    vector<int> visit(N, 0);

    for (int i = 0; i < N - 1; i++)
    {

        int u, v, w;

        cin >> u >> v >> w;

        G[u - 1].push_back(v - 1);
        G[v - 1].push_back(u - 1);
        G_w[u - 1].push_back(w);
        G_w[v - 1].push_back(w);
    }

    dfs(0, G, G_w, visit, nagasa);

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

        if (nagasa[i] == 0)
        {

            cout << '1' << endl;
        }
        else
        {

            cout << '0' << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 15232
using System;
using System.Linq;

namespace Structured_Program_II
{
    class Matrix_Multiplication
    {
        static void Main(string[] args)
        {
            var size = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var mat1 = new int[size[0]][];
            for (int i = 0; i < mat1.Length; i++)
                mat1[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var mat2 = new int[size[1]][];
            for (int i = 0; i < mat2.Length; i++)
                mat2[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            for (int i = 0; i < size[0]; i++)
                for (int j = 0; j < size[2]; j++)
                {
                    long res = 0;
                    for (int k = 0; k < size[1]; k++)
                        res += mat1[i][k] * mat2[k][j];
                    Console.Write(res);
                    if (j != size[2] - 1) Console.Write(" ");
                    else Console.WriteLine();
                }
        }
    }
}

Measured memory_bytes: 9876
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n>>a1>>a2;
    cout<<(n-a2)/(a2+a1);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

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

int H,W;
vector < string > S;

ll cntW;
ll cntB;
bool used[410][410];

void dfs (int x, int y)
{ 
    queue < pair < int,int > > sta;
    sta.push(make_pair(x,y));

    while (sta.size() > 0) {
        int nx = sta.front().first;
        int ny = sta.front().second;
        sta.pop();
        if (used[nx][ny]) continue;
        used[nx][ny] = true;
        if (S[nx][ny] == '#') {
            cntB++;
        } else {
            cntW++;
        }
        REP(i,4) {
            int nnx = nx + dx[i];
            int nny = ny + dy[i];
            if (nnx < 0 || nny < 0 || nnx >= H || nny >= W) continue;
            if (S[nnx][nny] == S[nx][ny]) continue;
            sta.push(make_pair(nnx, nny));
        }
    }
}

int main ()
{
    cin >> H >> W;
    S.resize(H);
    REP(i,H) cin >> S[i];

    REP(i,410) REP(j,410) used[i][j] = false;

    ll ans = 0;
    REP(x,H) REP(y,W) {
        cntW = 0;
        cntB = 0;
        if (!used[x][y]) {
            dfs(x,y);
            ans += cntW * cntB;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
import sys
from heapq import heappush,heappop,heapify
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    sushies=[]
    for i in range(N):
        t,d=map(int,input().split())
        sushies.append((d,t-1))
    sushies.sort()
    b=[False]*N
    overlappedsushi=[]
    ans=0
    n=0
    for i in range(K):
        sushi=sushies.pop()
        if b[sushi[1]]:
            heappush(overlappedsushi,sushi)
            ans+=sushi[0]
        else:
            b[sushi[1]]=True
            ans+=sushi[0]
            n+=1
    ans+=n**2
    tmp=ans
    while overlappedsushi:
        worstsushi=heappop(overlappedsushi)
        tmp-=worstsushi[0]
        while sushies:
            bestsushi=sushies.pop()
            if not b[bestsushi[1]]:
                break
        else:
            break
        n+=1
        tmp+=bestsushi[0]
        tmp+=n*2-1
        b[bestsushi[1]]=True
        ans=max(ans,tmp)
    print(ans)

    

if __name__ == '__main__':
    main()


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

int main() {
    int x;
    cin >> x;
    string ans = "ABC";
    if(x >= 1200)
        ans = "ARC";
    cout << ans << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
    string S;
    string T;
    cin >> S >> T;

    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if (S.at(i) == T.at(i))
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void) {
	string str;
	getline(cin, str);

	for (int i = 0; i < str.length() / 2; i++) {
		char c;
		c = str[i];
		str[i] = str[str.length() - 1 - i];
		str[str.length() - 1 - i] = c;
	}

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
void E(){puts("0");exit(0);}
const int N=1505,mo=998244353,iv2=mo+1>>1;
inline void add(int&a,const int&b){a+=b-mo;a+=a>>31&mo;}
int n,i,j,g[N],aa[N];
char c[N][N];
vector<int>e[N][N];
int tp[N][N];
bool bb[N];
int gfa(int x){return g[x]==x?x:g[x]=gfa(g[x]);}
inline int solve(vector<int>v){
	for(int i:v)for(int j:v)if(i<j){
		bool fl1=0,fl2=0;
		for(int x:e[i][j])fl1|=x=='o',fl2|=x=='x';
		if(fl1 && fl2)E();
		tp[i][j]=fl1?1:fl2?0:-1;
	}
	int ans=1;
	if(v.size()&1){
		for(i=0;i<v.size();++i)for(j=i+1;j<v.size();++j){
			int w=tp[v[i]][v[j]];
			if(w==-1)g[gfa(v[i])]=gfa(v[j]);
				else aa[v[i]]^=w,aa[v[j]]^=w;
		}
		static int b[N],ec[N],vc[N];
		for(i=0;i<v.size();++i)b[gfa(v[i])]^=aa[v[i]],++vc[gfa(v[i])];
		for(int i:v)if(b[i])E();
		for(i=0;i<v.size();++i)for(j=i+1;j<v.size();++j)if(tp[v[i]][v[j]]==-1)++ec[gfa(v[i])];
		for(int i:v)if(gfa(i)==i)for(int j=vc[i];j<=ec[i];++j)ans=2ll*ans%mo;
	}else{
		for(i=0;i<v.size();++i)for(j=i+1;j<v.size();++j)if(tp[v[i]][v[j]]==-1)ans=2ll*ans%mo;
	}
	return ans;
}
int main(){
	scanf("%d",&n);for(i=1;i<n;++i)scanf("%s",c[i]+1);
	for(i=1;i<n;++i)for(j=1;j<n;++j){
		int p=abs(i-j),q=n-abs(n-j-i);
		if(p>q)swap(p,q);e[p][q].push_back(int(c[i][j]));
	}
	vector<int>ve1,ve2;
	for(i=0;i<=n;i+=2)ve1.push_back(i);for(i=1;i<=n;i+=2)ve2.push_back(i);
	for(i=0;i<=n;++i)g[i]=i;
	printf("%lld\n",1ll*solve(ve1)*solve(ve2)%mo);
}

Measured memory_bytes: 82048
import java.io.*;

class Main {
	public static void main(String[] args){
		int a, b;
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String buf = br.readLine();
			String[] line = buf.split(" ");
			
			a = Integer.parseInt(line[0]);
			String op = line[1];
			b = Integer.parseInt(line[2]);
			
			if(op.equals("?")) break;
			
			if(op.equals("+")) {
				System.out.println(a + b);
			} else if (op.equals("-")){
				System.out.println(a - b);
			} else if (op.equals("*")){
				System.out.println(a * b);
			} else if (op.equals("/")){
				System.out.println(a/b);
			}
		}
		} catch(Exception e){
		}
	}
}

Measured memory_bytes: 24228
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

int main()
{
    ///fastio;

    int n;
    cin>>n;

    int a[n], g;
    cin >> a[0];
    g=a[0];

    for(int i=1; i<n; i++)
    {
        cin>>a[i];
        g = __gcd(a[i], g);
    }
    cout << g <<"\n";
    return 0;
}



Measured memory_bytes: 3960
#include <bits/stdc++.h>
#include <ext/algorithm>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

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

/**************************************************************/

	int N;
	cin >> N;
	pair<int,int> array[N];

	int count;
	for(int i = 0; i < N; i++)
	{
		cin >> count;
		array[i] = {count,i};
	}

	sort(array, array+N);
	count = 0;
	for(int i = 0; i < N; i++)
		if(i%2 != array[i].second%2)
			count++;

	cout << count/2 << endl;
}

Measured memory_bytes: 1024
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 30 + 5;
vector<int> v[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        v[s[i] - 'a'].push_back(i);
    }
    ll n = s.size(), m = t.size();
    int last = -1;
    ll cnt = 0;
    for(auto i : t){
        int id = i - 'a';
        int yo = upper_bound(v[id].begin(), v[id].end(), last) - v[id].begin();
        if(v[id].size() == 0)
            return cout << -1, 0;
        if(yo == v[id].size()){
            cnt++;
            yo = 0;
        }
        last = v[id][yo];
    }
    cout << (cnt * n) + last + 1;
return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    string stmp;
    
    cin >> stmp;
    
    int posA, posZ;
    posA = 300000;
    posZ = -300000;
    
    for(int i = 0; i < stmp.size(); i++)
    {
        if (stmp[i]=='A' && posA > i)
        {
            posA = i;
        }
        if (stmp[i]=='Z' && posZ < i)
        {
            posZ = i;
        }
    }
    cout << posZ - posA + 1 << endl;
    return 0;
}

Measured memory_bytes: 832
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <sstream>
#include <climits>
#include <fstream>
#include <cmath>

using namespace std;

/// ********* debug template by Bidhan Roy *********

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const unordered_set< T > &v ) {
    os << "[";
    typename unordered_set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const unordered_map< F, S > &v ) {
    os << "[";
    typename unordered_map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    } 
    return os << "]";
}

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VB> VVB;
typedef vector<VI> VVI;
typedef vector<VC> VVC;
typedef vector<VLL> VVLL;
typedef vector<VD> VVD;
typedef vector<VS> VVS;

// TEMPLATE DEFINITIONS END

char c;

void read_input(){
    cin >> c;
}

void solve(){
    c++;
    cout << c << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read_input();
    solve();
    return 0;
}


Measured memory_bytes: 256
a, b, ab, x, y = gets.split.map(&:to_i)

z = [x, y].max * 2
puts 0.step(z, 2).map {|n_ab|
       n_a = [x - n_ab / 2, 0].max
       n_b = [y - n_ab / 2, 0].max
       a * n_a + b * n_b + ab * n_ab
     }.min

Measured memory_bytes: 2684
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=998244353;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
inline int pl(int x,int y){return (x+=y)>=mod?x-mod:x;}
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,s,a[262144],g[262144],g1[262144];
void fwt(int f[])
{
	int x,y;
	for(int i=0;i<n;++i)
		for(int j=0;j<1<<n;++j)
			if(j>>i&1)
			{
				x=f[j^(1<<i)],y=f[j];
				f[j^(1<<i)]=pl(x,y);
				f[j]=pl(x,mod-y);
			}
}
int main()
{
//	printf("%d\n",468683018ll*kpow(700939337,mod-2)%mod);
	scanf("%d",&n);
	for(int i=0;i<1<<n;++i)scanf("%d",&a[i]),s+=a[i];
	s=kpow(s,mod-2);
	for(int i=0;i<1<<n;++i)a[i]=1ll*a[i]*s%mod;
	fwt(a);
//	for(int i=0;i<1<<n;++i)printf("%d ",a[i]);printf("\n");
	for(int i=0;i<1<<n;++i)g[i]=kpow(mod+1-a[i],mod-2);//,g1[i]=1ll*a[i]*g[i]%mod*g[i]%mod;
//	for(int i=0;i<1<<n;++i)printf("%d ",g[i]);printf("\n");
//	for(int i=0;i<1<<n;++i)printf("%d ",g1[i]);printf("\n");
	fwt(g);//fwt(g1);
//	for(int i=0;i<1<<n;++i)printf("%d ",g[i]);printf("\n");
//	printf("0\n");
//	int c=kpow(1<<n+1,mod-2);
	for(int i=0;i<1<<n;++i)printf("%d\n",pl(g[0],mod-g[i]));
//	int g0v=kpow(g[0],mod-2);
//	for(int i=0;i<1<<n;++i)printf("%d\n",(1ll*g1[i]*g[0]+1ll*(mod-g[i])*g1[0])%mod*g0v%mod*g0v%mod);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

#define REP(i,n) for (int i=0;i<(n);++i)
#define REP2(i,n) for (int i=0;i<=(n);++i)
#define REP3(i,n) for (int i=1;i<=(n);++i)


int main() {

	int N;
	vector<int> a;

	cin >> N;
	REP(i, N) {
		int ai;
		cin >> ai;
		a.push_back(ai);
	}

	int res;
	res = 0;

	REP(i, N) {
		int ai;
		ai = a[i];
		while (ai % 2 == 0) {
			ai /= 2;
			++res;
		}
	}

	
	cout << res << endl;

	int end;
	cin >> end;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main(){
    int n;
    std::cin >> n;
    int s = 0, t = n;
    while(n){
        s += (n % 10);
        n /= 10;
    }
    if(t%s){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    REP(i, n){ cin >> a.at(i); }
    ll ans = 0;
    REP(i, n - 1){
        if(a.at(i) + a.at(i + 1) > x){
            const ll diff = a.at(i) + a.at(i + 1) - x;
            ans += diff;
            a.at(i + 1) -= min(diff, a.at(i + 1));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (ll i = (ll)b; i < (ll)e; i++)
#define forr(i, b, e)    for (ll i = (ll)b; i < (ll)e; i++)
ll faster_in(){ll r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);
const lldb PI = acos(-1);
#define tam 302000
ll fact[tam],invfact[tam];
const ll MOD=1e9+7;
ll getC(int n,int m)
{
    if (m>n)return 0;
    return (((fact[n]*invfact[m])%MOD)*invfact[n-m])%MOD;
}
ll pot(ll base,ll exp)
{
    base%=MOD;
    ll res=1;
    while(exp)
    {
        if (exp&1)
            res*=base,res%=MOD;
        base*=base,base%=MOD;
        exp/=2;
    }
    return res;
}
void initcomb()
{
    fact[0]=1;
    forr(i,1,tam)
    fact[i]=fact[i-1]*i,fact[i]%=MOD;
//    <<fact[tam-1]<<endl;

    invfact[tam-1]=pot(fact[tam-1],MOD-2);
    for(int i=tam-2;i>=0;i--)
        invfact[i]=invfact[i+1]*(i+1),invfact[i]%=MOD;
}


vector<int> g[tam];
ll ways[tam],hijos[tam];
ll initf(int num,int parent)
{
    hijos[num]=1;
    ll res=1;
    for(int v:g[num])
    {
        if (v==parent)continue;
        res*=initf(v,num);res%=MOD;
        hijos[num]+=hijos[v];
    }
    int m=hijos[num];
    for(int v:g[num])
    {
        if (v==parent)continue;
        res*=getC(m-1,hijos[v]);res%=MOD;
        m-=hijos[v];
    }
    return ways[num]=res;
}
ll answer[tam];
int n;
ll solve(int me,int pa,ll waysup)
{
    waysup%=MOD;
    ll aways= waysup*fact[ n-1-hijos[me] ];aways%=MOD;
    aways*=pot(ways[me],MOD-2);aways%=MOD;
    aways*=invfact[n-1];aways%=MOD;
    aways*=fact[hijos[me]];aways%=MOD;

    //<<aways<<' '<<me<<" <- "<<pa<<endl;
    ll myways=aways*fact[n-1];myways%=MOD;
    myways*=invfact[n-hijos[me]];myways%=MOD;

    for(int v:g[me])
    {
        if (v==pa)continue;
        myways*=ways[v];myways%=MOD;  
        myways*=invfact[hijos[v]];myways%=MOD;
    }
    answer[me]=myways;
    for(int v:g[me])
    {
        if (v==pa)continue;
            solve(v,me,myways);
    }
}
int main()
{
    //std::ios::sync_with_stdio(false); cin.tie(0);
    initcomb();
    //<<getC(0,0)<<' '<<getC(5,3)<<endl;
    int iz,der;
    cin>>n;
    forr(i,0,n-1)
    {
        cin>>iz>>der;
        g[iz].pb(der);
        g[der].pb(iz);
    }
    initf(1,1);
    answer[1]=ways[1];
    for(int v:g[1])
    {
        solve(v,1,answer[1]);
    }
    forr(i,1,n+1)
    {
        cout<<answer[i]<<endl;
    }
}
// PLUS ULTRA!

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

#define FOR(a, b, c) for (int a = (b), _for = (c); a < _for; ++a)
#define REP(a, n) FOR(a, 0, n)
#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int n;
vector<pii> v[20];

bool ok(int bm){
	REP(i,n){
		if (!(bm&(1<<i))) continue;
		for (auto par:v[i]){
			int x=par.x,y=par.y;
			int t=(bm&(1<<x));
			if (y==1 && t==0) return 0;
			if (y==0 && t!=0) return 0;
		}
	}
	return 1;
}

int main(){
	scanf ("%d",&n);
	REP(i,n){
		int x;
		scanf ("%d",&x);
		REP(_,x){
			int a,b;
			scanf ("%d%d",&a,&b);
			a--;
			v[i].pb({a,b});
		}
	}
	int sol=0;
	REP(i,(1<<n)){
		if (ok(i)) sol=max(sol,__builtin_popcount(i));
	}
	printf ("%d\n",sol);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, a, n) for(int i=a; i<n; ++i)
#define all(c) c.begin(), c.end()
#define INF 1e18+1

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n, 0);
  for (int i = 1; i <= n-1; ++i) {
    for (int j = i+1; j <= n; ++j) {
      int m = min(j-i, abs(x-i)+1+abs(y-j));
      ans[m]++;
    }
  }
  for (int i = 1; i < n; ++i) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int main() {
 int H,W,j,i,k;
 i=1;
 j=1;
 k=1;
 while(1){
  scanf("%d %d",&H,&W);
  if(H==0 && W==0) break;  
    
    while(j<H+1){        //tate

      while(i<W+1){      //yoko
        i=i+1;
	
	if(j%2==1){
	  if(k==1){
            printf("#");
	    k=k-1;
	  }else{
	    printf(".");
	    k=k+1;
	  }
	}
	if(j%2==0){
          if(k==1){
            printf(".");
	    k=k-1;
	  }else{
	    printf("#");
	    k=k+1;
	  }
        }
        
      }//yoko
      
      printf("\n");
      j=j+1;
      i=1;
      k=1;
    }//tate
    
    i=1;
    j=1;
    printf("\n"); 
 }//1
}//main


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

int main(){
  int i,j,n,m;
  while(cin >> n >> m){
    int a1[100000],a,c,ans;
    c = 0;
    ans = 0;
    for(i=0;i<n-1;i++) cin >> a1[i];
    for(i=0;i<m;i++){
      cin >> a;
      if(a > 0) for(j=c;j<c+a;j++) ans += a1[j];
      else for(j=c-1;j>=c+a;j--) ans += a1[j];
      c += a;
      while(ans < 0) ans += 100000;
      ans %= 100000;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include <cstdio>
#include <cstring>
using namespace std;

char S[10];
int len;

int main() {
  scanf("%s", S + 1);
  len = strlen(S + 1);
  for (int i = 1; i < len; ++i)
    if (S[i] == 'A' && S[i + 1] == 'C') {
      puts("Yes");
      return 0;
    }
  puts("No");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl X(n),Y(n),H(n);
        ll x,y,h;
        rep(i,n){
            cin>>X[i]>>Y[i]>>H[i];
            if(H[i]>0){
                x=X[i];
                y=Y[i];
                h=H[i];
            }
        }
        rep(i,101){
            rep(j,101){
                ll nowH=h+abs(x-i)+abs(y-j);
                rep(k,n){
                    if(H[k]!=max(nowH-abs(X[k]-i)-abs(Y[k]-j),0LL))break;
                    if(k==n-1){
                        cout<<i<<' '<<j<<' '<<nowH<<endl;
                        return 0;
                    }
                }
            }
        }
    }

Measured memory_bytes: 3660