akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) cout<<"Case "<<n<<": "
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define MAX 1000007
#define all(x)(x.begin(),x.end())
#define debug(x,c) cout<<x<<": "<<c<<" ";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
vi v[100005];
int vis[100005],c = 0,check = 0;
queue<int>q;
void bfs(int a,int src)
{
	vis[a] = src;
	q.push(src);
	while(!q.empty())
	{
	src = q.front();
	for(int x: v[src])
	{
		if(vis[x]==0)
		{
			c++;
			vis[x] = src;
			q.push(x);
		}
	}
	q.pop();
	}
}
int main()
{
	int n , m;
	cin>>n>>m;
	memset(vis,0,sizeof vis);
	FOR(i,m)
	{
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	bfs(1,1);
	if(c < n-1)
		cout<<"No"<<endl;
	else
	{
		cout<<"Yes"<<endl;
		for(int i = 2;i<=n;i++)cout<<vis[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 10520
#include<bits/stdc++.h>
#include<set>
#define lli long long int
using namespace std;
int main()
{
	lli n,k,i;
	cin>>n>>k;
	lli a[n],b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=k;i<n;i++){
		if(a[i]>a[i-k])
		cout<<"Yes\n";
		else
		cout<<"No\n";
	}
	
	return 0;
}

Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = (1 << 12);
const ll INF = 1e10;

int n, m;
ll cost[MX];

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i < MX; ++i) cost[i] = INF;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        int keys = 0;
        for (int j = 0; j < b; ++j) {
            int c; cin >> c;
            --c;
            keys += (1 << c);
        }
        // cout << i << ' ' << keys << '\n';
        for (int j = 0; j < MX; ++j) {
            if (cost[j] == INF) continue;
            // cout << "j: " << j << ' ' << (j | keys) << '\n';
            cost[(j | keys)] = min(cost[(j | keys)], cost[j] + a); 
            // cout << "cost " << j << ' ' << cost[(j | keys)] << '\n';
        }
    }
    cost[(1 << n) - 1] == INF ? cout << -1 : cout << cost[(1 << n) - 1];
}


Measured memory_bytes: 3684
def search(a, x):
    n = len(a)
    hi = n-1
    lo = 0
    while hi >= lo:
        med = (hi+lo)/2
        if a[med] == x:
            return True
        elif a[med] > x:
            hi = med-1
        else:
            lo = med+1
    return False

n = int(raw_input())
S = map(int, raw_input().split(' '))
q = int(raw_input())
T = map(int, raw_input().split(' '))

found = 0
for x in T:
    if search(S, x):
        found += 1

print found

Measured memory_bytes: 14860
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll a[n];
	rep(i,0,n) cin >> a[i];

	sort(a,a+n);
	cout << a[n-1]-a[0];
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class ABiscuitGenerator {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a,b,t;in>>a>>b>>t;
	    out<<t/a*b<<endl;

	}
};


int main() {
	ABiscuitGenerator solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3156
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    s=input()
    cunt=0
    for i in range(n-1):
        if s[i]!=s[i+1]:
            cunt+=1
    print(n-1-cunt+min(2*k,cunt))

if __name__=='__main__':
    main()

Measured memory_bytes: 3316
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)*}
    };
}

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

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

use std::collections::HashMap;

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut map: HashMap<usize, usize> = HashMap::new();
    map.insert(0, 0);
    let mut w = v.clone();
    w.sort();
    let mut sum = 0;
    let mut prev = 0;
    for i in 0..n {
        if w[i] == prev {
            continue;
        }
        sum += (w[i] - prev) * (n - i);
        map.insert(w[i], sum);
        prev = w[i];
    }
    let mut max = 0;
    for x in v {
        if x > max {
            println!("{}", map.get(&x).unwrap() - map.get(&max).unwrap());
            max = x;
        } else {
            println!("0");
        }
    }
}


Measured memory_bytes: 14588
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 100100
using namespace std;
int a[maxn];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	map<int,bool>mp;
	for(int i=n-1;m>0&&i>=0;i--)
	{
		if(mp.find(a[i])==mp.end())
		{
			mp[a[i]]=true;
			printf("%d\n",a[i]);
			m--;
		}
	}
}


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

int main()
{
  string S;

  cin >> S;

  int S1 = stoi(S.substr(0, 2));
  int S2 = stoi(S.substr(2, 2));

  if (S1 > 0 && S1 <= 12 && S2 > 0 && S2 <= 12)
  {
    cout << "AMBIGUOUS" << endl;
  }
  else if (S1 > 0 && S1 <= 12)
  {
    cout << "MMYY" << endl;
  }
  else if (S2 > 0 && S2 <= 12)
  {
    cout << "YYMM" << endl;
  }
  else
  {
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 3612
N, K = map(int, input().split())
A = list(map(int, input().split()))
zero_count = [0 for i in range(50)]
for x in A:
    for i in range(50):
        zero_count[i] += 1 - (x >> i) & 1

ans = sum(A)
res = 0
for x in A:
	res+= (K^x)
ans =max(ans,res)    
K_bit_1 = [False for i in range(50)]
for i in range(49, -1, -1):
    if K >> i & 1:
        K_bit_1[i] = True

for x in range(50):
    if K_bit_1[x] == True:
        sub_ans = 0
        for i in range(49, x, -1):
            if K_bit_1[i]:
                sub_ans += (zero_count[i])*(1 << i)
            else:
                sub_ans += (N-zero_count[i])*(1 << i)
        sub_ans += (N-zero_count[x])*(1 << x)
        for j in range(x-1, -1, -1):
            sub_ans += max(N-zero_count[j], zero_count[j])*(1 << j)
        ans = max(sub_ans, ans)
print(ans)


Measured memory_bytes: 87448
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N,K;cin >> N >> K;
    vector<LL> P(N);
    rep(i,N){
        LL tmp;cin >> tmp;
        P[i] = tmp -1;
    }
    vector<LL> C(N);
    rep(i,N)cin >> C[i];

    vector<LL> onecy_val(N);
    vector<LL> onecy_ct(N);

    rep(i,N){   // (N^2) で前処理
        LL tmp = C[P[i]];
        LL now = P[i];
        LL ct = 1;
        while(now != i){
            ct++;
            tmp += C[P[now]];
            now = P[now];
        }
        onecy_val[i] = tmp;
        onecy_ct[i] = ct;        
    }

   // rep(i,N)cout << onecy_val[i] << " " << onecy_ct[i] << endl;
    LL ans = -100000000000000000;
    rep(i,N){   // i はスタート地点
        LL val = onecy_val[i];
        LL ct = onecy_ct[i];
        LL tmp = 0;
        if(K >= ct){
            if(val > 0){

                tmp += ((K/ct)-1)*val;
                LL now = i;
                ans = max(ans,tmp);
                rep(j,K-((K/ct)-1)*(ct)){
                    tmp += C[P[now]];
                    now = P[now];
                    ans = max(ans,tmp);
                }
            }
            else if(val <= 0){
                LL now = i;
                rep(j,N){
                    tmp += C[P[now]];
                    now = P[now];
                    ans = max(ans,tmp);
                }
            }
        }
        else{
            LL now = i;
            rep(j,K){
                tmp += C[P[now]];
                now = P[now];
                ans = max(ans,tmp);
            }            
        }
        ans = max(ans,C[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3764
import java.util.*;
import java.math.*;
import java.math.BigInteger;
class ppo implements Comparable<ppo>{
	int a,b;
	public ppo(int a,int b) {
		this.a=a;
		this.b=b;
	}
	public int compareTo(ppo other) {
		return this.a-other.a;
	}
}
public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static int n, m,c;
	static String s;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n=cin.nextInt();m=cin.nextInt();
		ppo arr[] =new ppo [maxn];
		for(int i=1;i<=n;i++) {
			arr[i]=new ppo(cin.nextInt(),cin.nextInt());
		}
		Arrays.sort(arr,1,n+1);
		int num=0;
		long ans=0;
		for(int i=1;i<=n;i++) {
			int ret=Math.min(m-num, arr[i].b);
			num+=ret;
			ans+=(long)ret*(long)arr[i].a;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 89848
// https://atcoder.jp/contests/abc092/tasks/abc092_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d, x, t;
    cin >> n >> d >> x;
    int ans = x;
    REP(i, n) {
        cin >> t;
        ans += ceil((double)d / t);
    }
    cout << ans << endl;
    return 0;
}

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

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2+2], R[MAX / 2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  // L[0...n1], R[0...n2] を生成
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> A[i];
  }
  mergeSort(A, n, 0, n);

  for (i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << cnt << endl;

  return 0;
}


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

string days[7] = { "Wednesday", "Thursday", "Friday", "Saturday",
                   "Sunday", "Monday", "Tuesday" };

int md[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int main() {

  int m,d;
  while(true) {
    cin>>m>>d;
    if(!m&&!d) break;

    int res=0;
    for(int i=0; i<m-1; i++)
      res += md[i];

    res += d;

    cout<<days[res%7]<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(x);
    LL ans = x / 500 * 1000 + x % 500 / 5 * 5;
    co(ans);
    return 0;
}

Measured memory_bytes: 256
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define num 10000000
#define root 10000
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)

using namespace std;

int main()
{
  int a,b,p;
  cin>>a>>b>>p;
  int x=0;
  forll(i,a,b,1)
  {
      if(i%p==0) x++;
  }
  cout<<x<<"\n";
}


Measured memory_bytes: 3576
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <sstream>
#include <algorithm>
#include <tr1/unordered_map>
using namespace std;
#define map tr1::unordered_map
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
int H,W;
char MAP[20][20];
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
 
bool input(){
    cin>>H>>W;
    if(H==0&&W==0)return false;
    REP(y,H){
        string t;
        cin>>t;
        REP(x,W){
            MAP[x][y]=t[x];
        }
    }
    return true;
}
map<string,int> res;
void solve(int x,int y,int d){
    string s;
    int nx=x,ny=y;
    do{
        s.push_back(MAP[nx][ny]);
        if(x==nx&&y==ny&&d==0)res[s]++;
        else if(x!=nx||y!=ny)res[s]++;
        nx=nx+dx[d]+W;
        ny=ny+dy[d]+H;
        nx%=W;
        ny%=H;
    }while((nx!=x||ny!=y));
}
int main() {
    while(input()){
        res.clear();
        REP(x,W){
            REP(y,H){
                REP(k,8){
                    solve(x,y,k);
                }
            }
        }
        string ans="";
 
        FOR(it,res){
            if(it->first.size()==1)continue;
            if(it->second>1){
                string r=it->first;
                if(r.size()>ans.size()){
                    ans=r;
                }else if(r.size()==ans.size()){
                    ans=min(ans,r);
                }
            }
        }
        if(ans=="")ans="0";
        cout<<ans<<endl;
    }
 
    return 0;
}

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

int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  cout<<(char)((int)(s1.at(0))+('A'-'a'));
  cout<<(char)((int)(s2.at(0))+('A'-'a'));
  cout<<(char)((int)(s3.at(0))+('A'-'a'));
  cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define INF 1<<30
#define MAX 1000000
using namespace std;
         
struct edge {
  int from,to,cost;
};
       
edge es[MAX];
       
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
       
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
          
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    int j=0;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
    d[e.to] = d[e.from] + e.cost;
    j=1;
      }
    }
    if(j==0)break;
  }
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  return 0;
}



Measured memory_bytes: 8916
N, K = map(int, input().split())
X = list(map(int, input().split()))


def comp(k, lst):
    temp =10**9
    for i in range(N-k+1):
        temp = min(temp, min(abs(lst[i]-lst[i+k-1])+abs(lst[i]), abs(lst[i]-lst[i+k-1])+abs(lst[i+k-1])))
    return temp

print(comp(K, X))

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



int main(){
	int a,b,n;
	cin>>n>>a>>b;

	int x=0;
	
	for(int i=0;i<2;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				for(int l=0;l<10;l++){
					for(int m=0;m<10;m++){
						if(i+j+k+l+m>=a && i+j+k+l+m<=b && 10000*i + 1000*j + 100*k + 10*l + m<=n){
							x = x + (10000*i + 1000*j + 100*k + 10*l + m);
						}
					}
				}
			}
		}
		
	}


	
	cout << x;
	
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


int main(){
	int K, S, ans=0;
	cin >> K >> S;
	REP(i, K+1) REP(j, K+1) {
		ans += (0 <= S-i-j && S-i-j <= K);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n, 0), b(n, 0);
  rep(i, n) {
    ll p;
    cin >> p;
    p--;
    a[p] += i;
  }
  rep(i, n) {
    a[i] += 5e8 + 21000 * i;
    b[i] += 5e8 - 21000 * i;
  }
  rep(i, n) cout << a[i] << (i == n - 1 ? '\n' : ' ');
  rep(i, n) cout << b[i] << (i == n - 1 ? '\n' : ' ');
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

void rot(string &s) {
  char c = s.back();
  for (int i = LEN(s)-1; i > 0; --i) {
    s[i] = s[i-1];
  }
  s[0] = c;
  return;
}

signed main()
{
  string s, t;
  cin >> s >> t;

  bool f = false;
  for (int i = 0; i < LEN(s); ++i) {
    rot(s);
    f |= (s == t);
  }

  puts(f ? "Yes" : "No");

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

int main()
{
	string s,t;cin>>s>>t;ri x=0;
	rep(i,0,2){
		if(s[i]==t[i]) ++x;
	}
	cout<<x;
	return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n + 1];
        int b[] = new int[n];
        for (int i = 0; i < n + 1; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        long ans = 0;
 
        for (int i = 0; i < n; i++) {
            if (a[i] < b[i]) {
                ans += a[i];
                b[i] -= a[i];
                if (a[i + 1] < b[i]) {
                    ans += a[i + 1];
                    a[i + 1] = 0;
                } else {
                    a[i + 1] -= b[i];
                    ans += b[i];
                }
            } else {
                ans += b[i];
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 85412
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int main(void)
{
    string s;
    cin >> s;
    vector<vector<int>> v(26);
    for (int i = 0; i < (int)s.size(); ++i)
    {
        v[s[i] - 'a'].push_back(i + 1);
    }

    for (int i = 0; i < 26; ++i)
    {
        int left = 0, right = (int)v[i].size() - 1; //v[left], v[right]はidxを指す.
        //left = 0~(v[i].size() - 1)

        while (left < right)
        {
            if ((v[i][right] - v[i][left] + 1) / 2 + 1 <= ((right + 1) - left))
            {
                cout << v[i][left] << " " << v[i][right] << endl;
                return 0;
            }

            if (v[i][left + 1] - v[i][left] > v[i][right] - v[i][right - 1])
            {
                left++;
            }
            else
            {
                right--;
            }
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	string n;
	cin >> n;
	for (int i = 0; i < 3; i++) {
		if (n[i] == '1')n[i] = '9';
		else if (n[i] == '9')n[i] = '1';
	}

	cout << stoi(n) <<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

# from numba import jit
# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    d = len(s)

    dp = [[0] * 13 for _ in range(d)]

    x = s[0]
    if x == "?":
        for i in range(10):
            nummod = (i * pow(10, d - 1, 13)) % 13
            dp[0][nummod] = 1
    else:
        nummod = (int(x) * pow(10, d - 1, 13)) % 13
        dp[0][nummod] = 1

    for i in range(1, d):
        x = s[i]
        if x == "?":
            for j in range(10):
                nummod = (j * pow(10, d - i - 1, 13)) % 13
                for k in range(13):
                    count = dp[i - 1][k]
                    nextmod = (k + nummod) % 13
                    dp[i][nextmod] += count
                    dp[i][nextmod] = dp[i][nextmod] % MOD
        else:
            nummod = (int(x) * pow(10, d - i - 1, 13)) % 13
            for j in range(13):
                count = dp[i - 1][j]
                nextmod = (j + nummod) % 13
                dp[i][nextmod] += count
                dp[i][nextmod] = dp[i][nextmod] % MOD

    print(dp[-1][5])


if __name__ == '__main__':
    main()


Measured memory_bytes: 61916
#include<bits/stdc++.h>
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define pb(a) push_back(a)
using namespace std;

int main()
{
    int a,p;
    cin>>a>>p;
    int res = 0;
    res += ( (a*3)+(p) )/2;
    cout<<res;
    return 0;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<"a > b"<<endl;
  }else if(a<b){
    cout<<"a < b"<<endl;
  }else{
    cout<<"a == b"<<endl;
  }
  return 0;
}


Measured memory_bytes: 2996
n,k = map(int,input().split())
d = {}
for i in range(n):
  a,b = map(int,input().split())
  if a in d:
    d[a] += b
  else:
    d[a] = b
cnt = 0
d_key = sorted(d)
for i in d_key:
  cnt += d[i]
  if cnt >= k:
    print(i)
    break

Measured memory_bytes: 10588
#include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cmath>

    using namespace std;
#define int long long

    const int mod = 998244353;

    int32_t main() {
        int n, k;
        cin >> n >> k;
        vector<int> dp(n, 0);
        dp[0] = 1;
        vector<int> ps(2, 0);
        ps[1] = 1;
        vector<int> l(k), r(k);
        for(int i = 0; i < k; ++i) {
            cin >> l[i] >> r[i];
        }
        for(int i = 1; i < n; ++i) {
            for(int j = 0; j < k; ++j) {
                int lg, rg;
                if (i - l[j] < 0) continue;
                rg = max(0ll, i - l[j]);
                lg = max(0ll, i - r[j]);
                dp[i] += ps[rg + 1] - ps[lg];
                dp[i] = (dp[i] + mod) % mod;
            }
            ps.push_back((ps.back() + dp[i]) % mod);
            dp[i] %= mod;
        }
        cout << dp[n - 1];
    }


Measured memory_bytes: 6908
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
ll a,b,n;
ll mx,num;
int main(){
//	while(1){
//		mx=num=0;
//		a=d,b=d,n=d;
//	//if(a>b)swap(a,b);
//	f(i,1,n){
//		ll k=floor((double)a*(double)i/(double)b)-a*floor((double)i/(double)b);
//		if(k>mx)mx=k;
//	}
//	f(i,1,n)
//		if(floor((double)a*(double)i/(double)b)-a*floor((double)i/(double)b)==mx)cout<<i<<" ";
//	cout<<endl;
//	}
	scanf("%lld%lld%lld",&a,&b,&n);
	if(a>=b){
		if(b-1<=n)cout<<a*(b-1)/b-a*((b-1)/b);
		else cout<<a*n/b-a*(n/b);
		return 0;
	}
	if(b-b/a<=n){cout<<a*(b-b/a)/b-a*((b-b/a)/b);return 0;}
	cout<<a*n/b-a*(n/b);
	return 0;
}


Measured memory_bytes: 3688
n, a, b = map(int, input().split())

ans = 0
for num in range(n):
  num += 1
  num_0 = num
  place_of_10000 = num//10000
  num -= 10000*place_of_10000
  place_of_1000 = num//1000
  num -= 1000*place_of_1000
  place_of_100 = num//100
  num -= 100*place_of_100
  place_of_10 = num//10
  num -= 10*place_of_10
  
  tmp = place_of_10000 + place_of_1000 + place_of_100 + place_of_10 + num
  if a<=tmp and tmp<=b:
    ans += num_0
    
print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;

    vector<LL> a(n);

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

    LL sum = 0;

    for(int i = 0; i < n; i++){
        sum ^= a[i];
    }

    vector<bool> mlboft(40,false);

    for(int i = 0; i < n; i++){
        LL ind = 1;

        while(a[i] > 0){
            if(a[i]&1){
                mlboft[ind] = true;
                break;
            }
            ind++;
            a[i] >>= 1;
        }
    }

    LL size = 0;
    LL tmp = sum;
    while(tmp > 0){
        size++;
        tmp >>= 1;
    }

    LL ans = 0;

    for(int i = size - 1 ; i >= 0 && ans >= 0; i--){
        LL j = 1 << i;
        if(sum&j){
            if(mlboft[i+1]){
                ans++;
                sum ^= j;
                sum ^= (j-1);
            }else{
                ans = -1;
            }
        }
    }

    cout << ans << endl;
    
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int a,b,c,d,i,t;
    cin >> a >> b >> c >> d;
    vector <long long int> vec;
    vec.push_back(a*c);
    vec.push_back(a*d);
    vec.push_back(b*c);
    vec.push_back(b*d);
    cout << *max_element(vec.begin(),vec.end()) << endl;
    return 0;
}



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

int main(){

  int N, M, ans;
  cin >> N;
  int T[N];
  for(int i=0; i<N; i++){
    cin >> T[i];
  }
  cin >> M;
  int P[M], X[M];
  for(int j=0; j<M; j++){
    cin >> P[j] >> X[j];
  }

  for(int i=0; i<M; i++){
    ans = 0;
    for(int j=0; j<N; j++){
      ans += P[i]==(j+1) ? X[i] : T[j] ;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int x = 0;
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = a;i<=b;i++){
        if(c % i == 0){
            x += 1;
        }
        else{
            x = x;
        }
    }
    cout<<x<<endl;
    
}


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

int main(void){
    int a, b;
    cin >> a >> b;

    if((a+b) % 3 == 0 || a % 3 == 0 || b % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EFOR(i,a,b) for (int i=(a);i<=(b);i++)
const ll MOD = (10*10*10*10*10*10*10*10*10+7);

    int A,B,C;
    int N,M;
    string D[100],ans;
    bool f=true;

int main(){
    cin>>N>>M;
    REP(i,N){cin>>D[i];}
    sort(D,D+N);
    REP(i,N){ans+=D[i];}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
ans1=X
for i in range(1,102):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Measured memory_bytes: 9136
N = int(input())
MOD = int(1e9+7)
A = [[[ [0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(102)]

A[0][3][3][3] = 1
# AGCT 0123
# x012
# x021
# x102
# 0x12
# 01X2
for x in range(N+1):
  for i in range(4):
    for j in range(4):
      for k in range(4):
        if A[x][i][j][k] == 0:
          continue
        for a in range(4):
          if (a == 2 and i == 1 and j == 0): continue
          if (a == 1 and i == 2 and j == 0): continue
          if (a == 2 and i == 0 and j == 1): continue
          if (a == 2 and i == 1 and k == 0): continue
          if (a == 2 and j == 1 and k == 0): continue
          A[x+1][a][i][j] = (A[x+1][a][i][j] + A[x][i][j][k]) % MOD
          
ans = 0
for i in range(4):
  for j in range(4):
    for k in range(4):
      ans = (ans + A[N][i][j][k]) % MOD
      
print(ans)

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

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

	ll ret = 0;
	rep(i, 3) {
		if(s.at(i) == t.at(i)) ++ret;
	}

	cout << ret << endl;

	return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int H, W;
char c[11][11];

string ans;
string dir = "RULD";
int dy[] = {0, -1, 0, 1}, dx[] = {1, 0, -1, 0};

bool inrange(int y, int x)
{
  return 0 <= y && y < H && 0 <= x && x < W;
}

bool solve(int y, int x, int d, int cnt)
{
  c[y][x] = '.';
  if(cnt == 0) return true;
  rep(i, 3) {
    int nd = (d+i+3) % 4, ny = y, nx = x;
    while(inrange(ny, nx) && c[ny][nx] == '.') {
      ny += dy[nd], nx += dx[nd];
    }
    ans += dir[nd];
    if(inrange(ny, nx) && solve(ny, nx, nd, cnt-1)) return true;
    ans.pop_back();
  }
  c[y][x] = 'o';
  return false;
}

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

  int sy, sx, cnt = 0;

  cin >> H >> W;
  rep(i, H) rep(j, W) {
    cin >> c[i][j];
    if(dir.find(c[i][j]) != -1) sy = i, sx = j;
    if(c[i][j] == 'o') cnt++;
  }

  ans = "";
  solve(sy, sx, dir.find(c[sy][sx]), cnt);
  cout << ans << endl;

  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	ll n, m;
    scanf("%lld %lld", &n, &m);
    vector<vector<ll>> w(8, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        ll x, y, z;
        scanf("%lld %lld %lld", &x, &y, &z);
        w[0][i] = +x + y + z;
        w[1][i] = +x + y - z;
        w[2][i] = +x - y + z;
        w[3][i] = +x - y - z;
        w[4][i] = -x + y + z;
        w[5][i] = -x + y - z;
        w[6][i] = -x - y + z;
        w[7][i] = -x - y - z;
    }
    ll ans = 0;
    for (int i = 0; i < 8; i++) {
        sort(w[i].begin(), w[i].end());
        ll sum = 0;
        for (int j = 0; j < m; j++) {
            sum += w[i][j];
        }
        ans = max(ans, abs(sum));
        
        reverse(w[i].begin(), w[i].end());
        sum = 0;
        for (int j = 0; j < m; j++) {
            sum += w[i][j];
        }
        ans = max(ans, abs(sum));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
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")
  };
}

fn main() {
  input! {
    a: [[i32; 3]; 3],
    n: i32, b: [i32; n]
  }
  
  let mut stat: Vec<Vec<bool>> = vec![vec![false; 3]; 3];
  for i in 0..3 {
    for j in 0..3 {
      if b.contains(&a[i][j]) {
          stat[i][j] = true;
      }
    }
  }
  
  if stat.contains(&vec![true; 3]) {
    println!("Yes");
    return;
  }
  
  for i in 0..3 {
    if !vec![stat[0][i], stat[1][i], stat[2][i]].contains(&false) {
      println!("Yes");
      return;
    }
  }
  
  if
    stat[1][1] &&
    (!vec![stat[0][0], stat[2][2]].contains(&false) ||
    !vec![stat[2][0], stat[2][0]].contains(&false)) {
    println!("Yes");
    return;
  }
  
  println!("No");
}

Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
const long long MOD = 1000000007;
long long O = 1, fc[251], fi[251];
int N, M, K, vi[51];
int head[51], next[201], to[201], E;
long long POWER(long long a, long long b)
{
	long long r = 1;
	for (; b; b >>= 1)
	{
		if (b & 1)
			r = r * a % MOD;
		a = a * a % MOD;
	}
	return r;
}
long long circle(int len)
{
	static long long f[51];
	for (int i = 1; i <= len; i++)
		if (len % i == 0)
			f[i] = POWER(K, i);
	for (int i = 1; i <= len; i++)
		if (len % i == 0)
			for (int j = 1; j < i; j++)
				if (i % j == 0)
					f[i] = (f[i] - f[j] + MOD) % MOD;
	long long R = 0;
	for (int i = 1; i <= len; i++)
		if (len % i == 0)
			R = (R + f[i] * POWER(i, MOD - 2)) % MOD;
	return R;
}
inline long long C(int x, int y)
{
	return fc[x] * fi[y] % MOD * fi[x - y] % MOD;
}
void DFS(int start)
{
	static int fa[51], fe[51], dep[51], his[51], cov[51], more[51], con[51], belong[51], count[51];
	static int q[51], ue[51];
	static std::pair < int, int > me[101];
	int nme = 0;
	int D = 1, TIME = 0;
	q[1] = start;
	ue[1] = head[start];
	vi[start] = 1;
	his[++TIME] = start;
	while (D)
	{
		if (ue[D] + 1 >> 1 == fe[q[D]])
			ue[D] = next[ue[D]];
		if (ue[D])
		{
			int To = to[ue[D]], Ue = ue[D];
			ue[D] = next[ue[D]];
			if (vi[To])
			{
				if (dep[q[D]] > dep[To])
					me[++nme] = { q[D], To };
			}
			else
			{
				fa[To] = q[D];
				fe[To] = Ue + 1 >> 1;
				dep[To] = D;
				his[++TIME] = To;
				vi[To] = 1;
				q[++D] = To;
				ue[D] = head[To];
			}
		}
		else
			D--;
	}
	for (int i = 1; i <= nme; i++)
	{
		cov[me[i].first]++;
		cov[me[i].second]--;
	}
	for (int i = TIME; i > 1; i--)
		cov[fa[his[i]]] += cov[his[i]];
	for (int i = 2; i <= TIME; i++)
	{
		if (cov[his[i]] == 0)
			O = O * K % MOD;
		more[his[i]] = cov[his[i]] > 1;
	}
	for (int i = 2; i <= TIME; i++)
		more[his[i]] += more[fa[his[i]]];
	for (int i = 1; i <= nme; i++)
		if (more[me[i].first] - more[me[i].second] == 0)
			O = O * circle(dep[me[i].first] - dep[me[i].second] + 1) % MOD;
		else
		{
			con[me[i].first]++;
			int u = me[i].first;
			while (fa[u] != me[i].second)
				u = fa[u];
			con[u]--;
		}
	for (int i = TIME; i > 1; i--)
		con[fa[his[i]]] += con[his[i]];
	for (int i = 2; i <= TIME; i++)
		count[belong[his[i]] = con[his[i]] ? belong[fa[his[i]]] : his[i]]++;
	for (int i = 1; i <= nme; i++)
		if (more[me[i].first] - more[me[i].second])
			count[belong[me[i].first]]++;
	for (int i = 2; i <= TIME; i++)
		if (count[his[i]] > 1)
			O = O * C(K + count[his[i]] - 1, count[his[i]]) % MOD;
}
int main()
{
	scanf("%d%d%d", &N, &M, &K);
	fc[0] = fi[0] = fi[1] = 1;
	for (int i = 2; i <= K + M; i++)
		fi[i] = (MOD - MOD / i) * fi[MOD % i] % MOD;
	for (int i = 1; i <= K + M; i++)
	{
		fc[i] = fc[i - 1] * i % MOD;
		fi[i] = fi[i - 1] * fi[i] % MOD;
	}
	for (int i = 1, u, v; i <= M; i++)
	{
		scanf("%d%d", &u, &v);
		next[++E] = head[u], to[E] = v, head[u] = E;
		next[++E] = head[v], to[E] = u, head[v] = E;
	}
	for (int i = 1; i <= N; i++)
		if (!vi[i])
			DFS(i);
	printf("%lld\n", O);
	return 0;
}


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

int main() {
    int k, a, b;
    cin >> k;
    cin >> a >> b;

    int c = 0;

    for (int i = a; i < b + 1; i++) c += i % k == 0;

    if (c) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
s = list(input())
t = list(input())
start = 0
count = 0
max_count = 0
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] == t[j]:
      count = count + 1
  if max_count < count:
    max_count = count
  count = 0
ans = len(t) -max_count
print(ans)

Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    string ans = a+b;
    int n = stoi(ans);
    int sqrtn = sqrt(n);
    if(sqrtn*sqrtn == n){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long X;
    cin >> X;
    
    long long int e=1e9, s=0;
    long long int i = (e-s)/2;
    
    while(!(((i-1)*i)/2<X && ((i+1)*i)/2>=X)) {
        if(((i-1)*i)/2>=X) {
            e = i;
            i = (e-s)/2 + s;
        } else if(((i+1)*i)/2<X) {
            s = i;
            i = (e-s)/2 + s;
        }
        
        // cout << i << endl;
    }
    
    cout << i << endl;

    return 0;
    
}

Measured memory_bytes: 256
import collections

def gcd(a,b):
    if a < b:
        a, b = b, a
    q = a // b
    r = a - q * b
    if r == 0:
        return b
    else:
        return gcd(b,r)

K = int(input())

a = []

for i in range(1,K+1):
    for j in range(1, K+1):
        a.append(gcd(i,j))
        
col = collections.Counter(a)

sum = 0
for k in range(1, K+1):
    for key, value in col.items():
         sum += gcd(k, key) * value
print(sum)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

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

struct acc {
  vector<lli> sum;
  acc(vector<lli> v) {
    sum.push_back(0);
    each (i, v) {
      sum.push_back(sum.back() + i);
    }
  }
  lli query(lli begin, lli end) {
    return sum[end] - sum[begin];
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  const lli mod = 1e9 + 7;
  const string t = "ABC_";
  string s;
  while (cin >> s) {
    vector<lli> a(s.size(), 0);
    vector<lli> c(s.size(), 0);
    vector<lli> h(s.size(), 0);
    for (int i = 0; i < s.size(); ++i) {
      a[i] += (s[i] == 'A');
      c[i] += (s[i] == 'C');
      h[i] += (s[i] == '?');
    }

    map<int, lli> p3;
    lli prev = 1;
    for (int i = 0; i < 1e5; ++i) {
      p3[i] = prev;
      (prev *= 3) %= mod;
    }
    p3[-1] = 0;
    
    acc acc_a(a);
    acc acc_c(c);
    acc acc_h(h);

    lli sum = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == 'B' || s[i] == '?') {
        lli A = acc_a.query(0, i);
        lli AH = acc_h.query(0, i);

        lli C = acc_c.query(i + 1, s.size());
        lli CH = acc_h.query(i + 1, s.size());
        
        // ?B?
        {
          lli x = AH * CH;
          lli y = p3[AH - 1] * p3[CH - 1];
          x %= mod;
          y %= mod;
          (sum += (x * y) % mod) %= mod;
        }
        // AB?
        {
          lli x = A * CH;
          lli y = p3[AH] * p3[CH - 1];
          x %= mod;
          y %= mod;
          (sum += (x * y) % mod) %= mod;
        }
        // ?BC
        {
          lli x = AH * C;
          lli y = p3[AH - 1] * p3[CH];
          x %= mod;
          y %= mod;
          (sum += (x * y) % mod) %= mod;
        }
        // ABC
        {
          lli x = A * C;
          lli y = p3[AH] * p3[CH];
          x %= mod;
          y %= mod;
          (sum += (x * y) % mod) %= mod;
        }
      }
    }
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 13100