akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret; for (VType i = start; i < end; i++) ret.push_back(i); return move(ret);
}

int main() {
    int const n(in());
    int p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];            
    } 
    int count = 0;

    for (int i = 1; i < (n - 1); i++) {
        if (p[i] < p[i - 1]) {
            if (p[i + 1] <= p[i]) {
                count++;
            }
        } else if (p[i] < p[i + 1]) {
            if (p[i - 1] <= p[i]) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}




Measured memory_bytes: 256
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    b = 0
    c = 0
    d = 0
    for a in A:
        if a == b:
            c += 1
        if a != b:
            d += c//2
            b = a
            c = 1
    d += c//2
    b = a
    c = 0
    print(d)
    

if __name__ == '__main__':
    solve()

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

int f(int N) {
    int f_N = 0;
    int i = 1;
    for (; i * i < N; i++) {
        if (N % i == 0) {
            f_N += 2;
        }
    }

    if (i*i == N) {
        f_N++;
    }
    return f_N;
}

void Main() {
    // input
    int N;
    cin >> N;


    // process
    int ans = 0;
    for (int i = 1; i < N; i++) {
        ans += f(N-i);
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(int H, int M) {
    while (true) {
        cin >> H >> M;
        if (H == 0 && M == 0){
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < M; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3076
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.lang.Long.*;
import static java.lang.System.*;
import static java.lang.Math.*;
import java.io.PrintWriter;

public class Main {
	public static long MAX = (long)2e12;
	public static void main(String[] args) {
		int i, j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		long x = parseLong(sc.next());
		long[] a = new long[n];
		for (i = 0; i < n; i++) {
			a[i] = parseLong(sc.next());
		}
		sc.close();
		long[] b = new long[n];
		for (i = 0; i < n-1; i++) {
			b[i] =  a[i] + a[i+1];
		}
		long cnt=0;
		for (i = 0; i < n-1; i++) {
			long tmp = Math.max(b[i] - x,0);
			cnt+=tmp;
			if(i==n-2) break;
			b[i+1] -= Math.min(a[i+1],tmp);
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 48284
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int sutexia_ai_konnpu(const char* a, const char* b) {
	for (;;) {
		int aa = tolower((unsigned char)*a);
		int bb = tolower((unsigned char)*b);
		if (aa > bb) return 1;
		if (aa < bb) return -1;
		if (aa == 0 && bb == 0) return 0;
		a++;
		b++;
	}
}

int main(void) {
	char W[16];
	char T[1024];
	int count = 0;
	if (scanf("%15s", W) != 1) return 1;
	while (scanf("%1023s", T) == 1 && strcmp(T, "END_OF_TEXT") != 0) {
		if (sutexia_ai_konnpu(W, T) == 0) count++;
	}
	printf("%d\n", count);
	return 0;
}




Measured memory_bytes: 2096
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int w=sc.nextInt();int a=sc.nextInt();int b=sc.nextInt();
  System.out.println((Math.abs(a-b)<=w)?0:Math.abs(a-b)-w);
}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    int a[n];
    f(i,n) cin>>a[i];
    int ans = 0;
    f(i,n) ans += a[i];
    cout<<ans - n;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
g = [[-1]*n for _ in range(m)]
for i in range(m):
  s = list(map(int, input().split()))
  s.pop(0)
  for j in s:
    g[i][j-1] = 1
p = list(map(int, input().split()))

ans = 0
for i in range(2**n):
  switch = [0]*n
  for j in range(n):
    if ((i >> j) & 1):
      switch[j] = 1
  
  flag = True
  for j in range(m):
    cnt = 0
    for k in range(n):
      if g[j][k] == switch[k]:
        cnt += 1
    if cnt % 2 != p[j]:
      flag = False
  if flag:
    ans += 1

print(ans)

Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n;
  string s;
  cin >> n >> s;
  vector<int> a(n);
  REP(i,n) a[i] = s[i] == 'o'; // 0: x, 1: o

  // 4パターンを固定して考える: SS, SW, WW, WS
  for (string ans: {"SS", "SW", "WW", "WS"}) {
    for (int i = 1; i < n; i++) {
      if (ans[i] == 'S' ? a[i] : a[i]^1) ans += ans[i-1];
      else ans += ans[i-1] == 'S' ? 'W' : 'S';
    }

    int ok = 0;
    if (ans[0] == 'S' ? a[0] : a[0]^1) {
      ok = ans[1] == ans[n-1];
    } else {
      ok = ans[1] != ans[n-1];
    }
    if (ok && ans[0] == ans[n]) { COUT(ans.substr(0,n)); return 0; }
  }

  COUT(-1); // 存在しない
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	ll a;
	double in;
	cin >> a >> in;
	ll b = (in + 0.001) * 100;
	// cout << a << " " << b << endl;
	ll ans = (a * b) / 100;
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

using std::vector;
using std::string;

typedef long long lint;
typedef std::pair<int, int> pii;

int cnt[30];

int main() {
	string str; std::cin >> str;

	int ans = 123456789;
	for (int c = 'a'; c <= 'z'; c++) {
		string tmp = str;
		int cnt = 0;
		while (!str.empty()) {
			bool flag = false;
			for (int i = 0; i + 1< str.size(); i++)
				if (str[i] != str[i + 1]) flag = true;
			if (!flag) break;

			cnt++;
			string next;
			for (int i = 0; i +1 < str.size(); i++) {
				if (str[i] == c || str[i + 1] == c) {
					next.push_back(c);
				}
				else next.push_back(str[i]);
			}
			str = next;
		}
		ans = std::min(ans, cnt);
		str = tmp;
	}
	printf("%d", ans);

}

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

int main()
{
    ll N, A[85], T[85],kabu=0,m=1000;
    cin >> N;
    REP(i,N){
        cin >> A[i];
        if(i!=0&&A[i]>A[i-1]){
            T[i-1]=1;
        }else if(i!=0&&A[i]<A[i-1]){
            T[i-1]=2;
        }else{
            T[i-1]=0;
        }
    }
    T[N-1]=0;
    REP(i,N){
        if((i==N-1 && kabu>0) || (T[i]==2 && kabu>0)){
            m = m+kabu*A[i];
            kabu = 0;
        }
        else if(T[i]==1 && A[i]<=m){
            kabu = m/A[i];
            m = m % A[i];
        }
    }
    cout << m << endl;
    return 0;  
}


Measured memory_bytes: 3620
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
-- import           Data.Array.Unboxed
import qualified Data.ByteString.Char8 as BC
import           Data.List             (foldl')
import           Data.Maybe            (fromJust)
import qualified Data.Vector.Unboxed   as V

main :: IO ()
main = do
  s <- getLine
  [x, y] <- readInts
  putStrLn . showResult $ solve s x y

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

showResult True  = "Yes"
showResult False = "No"

solve :: String -> Int -> Int -> Bool
solve s x y = check dxs x && check (0:dys) y where
  (dxs, dys) = divide2 . map length $ splitOnT s

divide2 xs = (evens, odds) where
  xis   = xs `zip` [0 .. ]
  evens = [x | (x, i) <- xis, i `mod` 2 == 0]
  odds  = [x | (x, i) <- xis, i `mod` 2 == 1]

splitOnT :: String -> [String]
splitOnT = reverse . go [] [] where
  go acc1 acc2 []       = acc2 : acc1
  go acc1 acc2 ('T':xs) = go (acc2 : acc1) [] xs
  go acc1 acc2 (x:xs)   = go acc1 (x : acc2) xs

check :: [Int] -> Int -> Bool
check [] x = x == 0
check (d:ds) x = dp V.! (x + s) where
  dp = foldl' folder dp0 ds
  dp0 = V.generate (s * 2) (== d + s)
  -- dp0 = array (-s, s) $ (d, True) : [(i, False) | i <- [-s .. s], i /= d] :: UArray Int Bool


folder bs d = V.imap (\i _ -> bs `at` (i - d) || bs `at` (i + d)) bs
-- folder :: UArray Int Bool -> Int -> UArray Int Bool
-- folder bs d = array (-s, s) [(i, bs `at` (i - d) || bs `at` (i + d)) | i <- [-s .. s]]

s = 8001

at bs i = maybe False id $ bs V.!? i

-- at :: UArray Int Bool -> Int -> Bool
-- at bs i
--   | i < -s || s < i = False
--   | otherwise = bs ! i


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
 
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
	fast;
	ll h = 1;
	//cin >> h;
	while(h--){
	int x, y;
	cin >> x >> y;
	cout << 6-x-y;	
	}}

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

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

using namespace std;

int main(void)
{
  int N;
  int n = 1;

  cin >> N;

  while(N >= n * 2)
    n *= 2;

  cout << n << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vvi matmul(vvi v,vvi x,ll n){
    vvi nv(n,vi(n));
    rep(i,n)rep(j,n)rep(k,n)nv[i][j]=(nv[i][j]+v[i][k]*x[k][j])%mod;
    return nv;
}
void solve(vi&dp,vvi v,ll n,ll k){
    vvi nv(n,vi(n));
    rep(i,n)nv[i][i]++;
    ll bit=0;
    while((1ll<<bit)<=k){
        if(k>>bit&1)nv=matmul(nv,v,n);
        v=matmul(v,v,n);
        bit++;
    }
    vi ndp(n);
    rep(i,n)rep(j,n)ndp[i]=(ndp[i]+dp[j]*nv[j][i])%mod;
    dp=ndp;
}
int main(){
    ll n,k;cin>>n>>k;
    vvi v(n,vi(n));
    rep(i,n)rep(j,n)cin>>v[i][j];
    vi dp(n,1);
    solve(dp,v,n,k);
    ll sum=0;
    rep(i,n)sum=(sum+dp[i])%mod;
    out(sum);
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var w = cin.next().ToCharArray();
            var bk = new int[300];
            foreach (var c in w)
            {
                bk[c]++;
            }
            Console.WriteLine(bk.All(i => i%2==0 || i==0)?"Yes":"No");
        }
    }    

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}

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

bool palin(string str)
{
    string temp = str;
    reverse(temp.begin(),temp.end());
    
    return(temp == str);
}

bool fun(string str)
{
    int n=str.length();
    
    string a = str.substr(0,((n-1)/2));
   // cout<<a<<endl;
    
    string b  = str.substr(((n+3)/2)-1);
    
    //cout<<b<<endl;
    if(palin(a)&&palin(b)&&palin(str))
    return true;
    
    else
    return false;
    
}

int main()
{
    
    string str;
    cin>>str;
    
    if(fun(str))
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
}

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

int main() {

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int n;
    cin>>n;

    int d[n];
    for (int i=0; i<n; i++){
        cin>>d[i];
    }
    int ans = 0;
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            ans += d[i]*d[j];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    ll x[n], y[n], h[n], idx;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] > 0) idx = i;
    }
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            ll t = h[idx] + abs(x[idx] - i) + abs(y[idx] - j);
            bool flag = true;
            for (int k = 0; k < n; k++) {
                int tmp = t - abs(x[k] - i) - abs(y[k] - j);
                tmp = max(tmp, 0);
                if (h[k] != tmp) flag = false;
            }
            if (flag) {
                cout << i << ' ' << j << ' ' << t << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

int main(){
  int n,d,a;
  cin>>n>>d>>a;
  vector<pair<int,int>> monsters;
  for(int i = 0;i<n;i++){
    int x,h;
    cin>>x>>h;
    h=(h+a-1)/a;
    monsters.emplace_back(x,h);
  }
  sort(monsters.begin(),monsters.end());
  
  int base=1;
  while(base<n){
    base*=2;  
  }
  vector<int> tree(2*base);
  for(int i=0;i<n;i++){
    tree[base+i]=monsters[i].second;
  }
  auto get_health = [&](int i){
    int total = 0;
    for(int j=base+i;j>=1;j/=2){
      total +=tree[j];
    }
    return total; 
  };
  auto add_interval = [&](int L,int R,int x){
    L+=base;
    R+=base;
    tree[L] += x;
    if(L != R){
      tree[R] += x;
    }
    while(L+1<R){
      if(L % 2==0){
        tree[L+1] +=x; 
      }
      if(R % 2==1){
        tree[R-1] += x;
      }
      L /= 2;
      R /= 2;
    }
  };
  long long int answer=0;
  for(int i = 0;i<n;i++){
    int myHealth = get_health(i);
    if(myHealth<=0){
      continue;
    }
    int low =i,high = n-1;
    int ok=-1;
    while(low<=high){
      int mid = low+((high-low)/2);
      if(monsters[mid].first<= monsters[i].first+2ll*d){
        ok=mid;
        low=mid+1;
      }
      else{
        high=mid-1;
      }
    }
    add_interval(i,ok,-myHealth);
    answer+= myHealth;
  }
  cout<<answer<<"\n";  
  
  return 0;
}

Measured memory_bytes: 3952
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  
  int product;
  product=a*b;
  
  string comment;
  if(product%2==0){
    cout<<"Even"<<endl;
  }else{
    cout<<"Odd"<<endl;
  }
  //cout<<comment<<endl;
  return 0;
}

  

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
using ulong = unsigned long;
using ll = long long;
ll mod = 1e9+7;
ll facts[(int)2e5+10];

ll modPow(ll base, ll ex, ll m) {
	ll ret = 1;
	while(ex){
		if(ex & 1){
			ret = ret * base % m;
		}
		ex >>= 1;
		base = base * base % m;
	}
	return ret;
}

ll modInv(ll n, ll m){
	return modPow(n, m-2, m);
}

ll modC(ll n, ll k, ll m){
	return facts[n] * modInv(facts[k] * facts[n-k] % m, m) % m;
}

ll solve(ll h, ll w, ll mod){
	return modC(h + w- 2, w - 1, mod);
}

void setFact(ll m){
	facts[0] = 1;
	for(int i=1;i<2e5+10;i++){
		facts[i] = facts[i-1] * i % m;
	}
}

int main(){
	int h, w, a, b;
	cin >> h >> w >> a >>b;
	setFact(mod);
	ll ans = 0, h1 = h - a, w1 = b + 1;
	while(w1 <= w && h1 >= 1){
		ans = (ans + solve(h1, w1, mod) * solve(h - h1 + 1, w - w1 + 1, mod))% mod;
		w1++;
		h1--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
void call(int n) {
	int i = 1;
CHECK_NUM:
	int x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
INCLUDE3:
	if (x % 10 == 3) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
	x /= 10;
	if (x) goto INCLUDE3;
END_CHECK_NUM:
	if (++i <= n) goto CHECK_NUM;

	cout << endl;
}
void solv() {

	int n,m;
	cin >> n >> m;
	ll tp[110][110];
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = 0; j < m; j++)
		{
			cin >> tp[i][j];
		}
	}

	ll b[110];
	for (size_t i = 0; i < m; i++)
	{
		cin >> b[i];
	}

	for (size_t i = 0; i < n; i++)
	{
		ll su = 0;
		for (size_t j = 0; j < m; j++)
		{
			su += tp[i][j] * b[j];
		}
		cout << su << endl;
	}
}

int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 3172
// AtCoder Beginner Contest 113 - Problem A: Discount Fare (https://beta.atcoder.jp/contests/abc113/tasks/abc113_a)
#include <bits/stdc++.h>

using namespace std;

void solve(int X, int Y)
{
    auto ans = X + Y/2;

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int X, Y;
    cin >> X >> Y;

    solve(X, Y);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int inf=1000000000;
    int n,m;
    cin>>n>>m;
    int N=1<<n;
    vector<vector<int>>dp(m+1,vector<int>(N,inf));
    dp[0][0]=0;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        int c[b];
        for(int j=0;j<b;j++){
            cin>>c[j];
            c[j]--;
        }
        for(int j=0;j<N;j++){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            int newj=j;
            for(int k=0;k<b;k++)newj|=(1<<c[k]);
            dp[i+1][newj]=min(dp[i+1][newj],dp[i][j]+a);
        }
    }
    if(dp[m][N-1]==inf)cout<<"-1"<<endl;
    else cout<<dp[m][N-1]<<endl;
    return 0;
}

Measured memory_bytes: 19344
#include <cstdio>
#include <utility>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

enum {N = 1000000};

int main() {
	array<int, N> s1, s2;
	iota(s1.begin(), s1.end(), 0);
	iota(s2.begin(), s2.end(), 0);
	for (int i = 1, n; (n = i * (i + 1) * (i + 2) / 6) < N; i++) {
		for (auto j = s1.begin() + n; j != s1.end(); j++)
			*j = min(*j, *(j - n) + 1);
		if (n % 2)
			for (auto j = s2.begin() + n; j != s2.end(); j++)
				*j = min(*j, *(j - n) + 1);
	}
	for (int n; (n = in());)
		outl(s1[n], ' ', s2[n]);
}


Measured memory_bytes: 10352
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main() {
	int n;
	scanf("%d\n", &n);
	auto vs = readln.chomp.split.to!(double[]);
	vs.sort!"a<b";
	writef("%0.10f", vs.reduce!((a, b) => (a + b) / 2));
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n, p[1000][3], i, j, sum[1000] = { 0 };
	//int start, kind[1000], k, ki = 0, h;
	int co = 0, h, k, temp, flag1, flag2;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < 3; j++) {
			scanf("%d", &p[i][j]);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < 2; j++) {
			for (k = j + 1; k < 3; k++) {
				if (p[i][j] > p[i][k]) {
					temp = p[i][j];
					p[i][j] = p[i][k];
					p[i][k] = temp;
				}
			}
		}
	}
	/*
	for (i = 0; i < n; i++) {
		for (j = 0; j < 3; j++) {
			printf("%d ", p[i][j]);
		}
		printf("\n");
	}*/

	for (i = 0; i < n-1; i++) {
		for (k = i + 1; k < n; k++) {
			flag1 = flag2 = 0;
			for (j = 0; j < 3; j++) {
				if (p[i][j] == p[k][j] && p[i][j] != 0) {
					if (j == 0) {
						flag1 = 1;
					}
					if (j == 1 && flag1 == 1) {
						flag2 = 1;
					}
					if (j == 2 && flag1 == 1 && flag2 == 1) {
						co++;
						for (h = 0; h < 3; h++) {
							p[k][h] = 0;
						}
					}
				}
			}
		}
	}
	printf("%d\n", co);
	return 0;
}



Measured memory_bytes: 2112
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;


int main(){
	int cnt=0;
	int n;
	cin>>n;
	REP(i,n){
		int a;
		cin>>a;
		while(a%2==0){
			cnt++;
			a/=2;
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
    H, W = map(int, input().split())
    m = []
    for _ in range(H):
        l = input()
        m.append(l)
    edge = []
    v = H * W
    for i in range(H):
        for j in range(W):
            t = i * W + j
            edge.append([10 ** 9] * v)
            if m[i][j] == '.':
                if i > 0 and m[i-1][j] == '.':
                    edge[t][(i-1) * W + j] = 1
                if j > 0 and m[i][j -1] == '.':
                    edge[t][i * W + j - 1] = 1
                if i < H-1 and m[i+1][j] == '.':
                    edge[t][(i + 1)*W + j] = 1
                if j < W - 1 and m[i][j+1] == '.':
                    edge[t][i * W + j + 1] = 1
    G = csgraph_from_dense(edge, null_value=10**9)
    d = floyd_warshall(G)
    m = 0
    for i in range(v):
        for j in range(v):
            if d[i][j] != float('inf') and d[i][j] > m:
                m = d[i][j]
    print(int(m))
main()
    


Measured memory_bytes: 17308
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[10][10];
int dp[2][177147];

int pown[20];

int get(int S, int i) {
  return S/pown[i]%pown[1];
}
inline int change(int S, int i, int x) {
  S -= get(S,i)*pown[i];
  S += x*pown[i];
  return S;
}
void init(int n, int m) {
  pown[0] = 1;
  REP(i,m) pown[i+1] = pown[i]*n;
}

int mod = 1e8 + 7;
int pre[10][10];

int main() {
  init(3,15);
  
  int h, w;
  while(cin >> h >> w) {

    REP(i,h)REP(j,w) {
      char c;
      cin >> c;
      a[i][j] = (c=='.'?0:c-'0');
    }

    REP(i,h) {
      int p = -1;
      REP(j,w) {
        pre[i][j] = p;
        if (a[i][j]) p = j;
      }
    }
    
    memset(dp,0,sizeof(dp));

    int *cur = dp[0];
    int *nxt = dp[1];

    cur[0] = 1;

    REP(y,h) {
      REP(x,w) {
        REP(S,pown[w+1]) nxt[S] = 0;
        REP(S,pown[w+1]) {
          if (x == 0 && get(S,w)) continue; // 右端に飛び出てる
          if (a[y][x] == 0) {
            nxt[S] = cur[S];
          } else {
            int rest = a[y][x] - get(S,w) - get(S,x);
            if (get(S,w)) {
              bool dame = 0;
              for (int i=pre[y][x]+1; i<x; ++i)
                if (get(S,i)) dame = 1;
              if (dame) continue;
            }
            for (int yoko=0; yoko<=min(2,rest); ++yoko) {
              int tate = rest - yoko;
              if (tate > 2) continue;
              int T = change(S,w,yoko);
              T = change(T,x,tate);
              nxt[T] = (nxt[T] + cur[S]) % mod;
            }
          }
        }
        swap(cur,nxt);
      }
    }
    cout << cur[0] << endl;
  }
}

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

int main(){
  int n, cnt;
  while(cin >> n){
    cnt = 0;
    for(int a = 0; a < 10; a++){
      for(int b = 0; b < 10; b++){
        for(int c = 0; c < 10; c++){
          for(int d = 0; d < 10; d++){
            if(a + b + c + d == n)
             cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }

}

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

string solve(long long int n)
{
  string s;
  long long int cnt=0,m=n,d;
  if(n==0)
    return "0";
  while(n!=0)
  {
      d=n%(-2);
      n/=(-2);
      //cout<<n<<" "<<d<<"\n";
      if(d<0)
      {
          d+=2;
          n++;
      }
      if(d==0)
        s+='0';
      else
        s+='1';
  }
  reverse(s.begin(),s.end());
  return s;
}


int main()
{
    ios_base::sync_with_stdio(false);

    long long int n;

    cin>>n;
    cout<<solve(n)<<"\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, k;
ll a[maxn], ans, sum[maxn], ps[maxn];

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

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		if (i)
			sum[i] = sum[i - 1], ps[i] = ps[i - 1];
		if (a[i] > 0)
			sum[i] += a[i];
		ps[i] += a[i];
	}
	for (int i = 0; i < n - k + 1; i++)
	{
		ans = max(ans, sum[n - 1] - (sum[i + k - 1] - (i ? sum[i - 1] : 0)));
		ans = max(ans, (i ? sum[i - 1] : 0) + ps[i + k - 1] - (i ? ps[i - 1] : 0) + sum[n - 1] - sum[i + k - 1]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#define ll long long
#include<bits/stdc++.h>

using namespace std;
int main() {
	int n,m;
    cin>>n>>m;
    string ans;
    vector<pair<int,char>> p(m);
    rep(i,m)
        cin>>p[i].first>>p[i].second;
    rep(i,n){
        ans+="n";
    }
    rep(i,m){
        if(p[i].second!=ans[p[i].first-1]){
            if(ans[p[i].first-1]=='n')
                ans[p[i].first-1]=p[i].second;
            else{
                cout<<"-1"<<endl;
                return 0;
            }
        }
    }
    rep(i,n){
        if(i==0&&ans[i]=='0'){
            if(ans.size()==1)
                ans='0';
            else{
                ans="-1";
                break;
            }
        }
        else if(ans[i]=='n'){
            if(i==0){
                if(ans.size()==1)
                    ans='0';
                else
                    ans[i]='1';       
            }
            else
                ans[i]='0';
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	int i,n,x,j;
	char buf[101];
	while(scanf("%s",buf)!=EOF)	{
		n=strlen(buf);
		for(i=0;i<n;i++)	{
			if(buf[i]!='@')	printf("%c",buf[i]);
			else {
				x=buf[i+1]-'0';
				for(j=0;j<x;j++)	{
					printf("%c",buf[i+2]);
				}
				i=i+2;
			}
		}
		printf("\n");
	}
	return 0;
}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
using P = pair<ll, ll>;

template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
#define VN(v) # v
#define print(a) cout << a << "#" << VN(a) << endl;
#define ldout fixed << setprecision(40) 

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vld x(n), y(n); rep(i, x.size()) cin >> x[i] >> y[i];
    if (n % 2) { cout << "NA" << endl; return 0; }
    ld xc = x[0] + x[n/2], yc = y[0] + y[n/2];
    rep(i, n/2) {
        if (abs(xc - (x[i] + x[i+n/2])) > EPS || abs(yc - (y[i] + y[i+n/2])) > EPS) {
            cout << "NA" << endl; 
            return 0;
        }
        xc = (x[i] + x[i+n/2]);
        yc = (y[i] + y[i+n/2]);
    }

    cout << ldout << xc/2 << " " << yc/2 << endl;

    return 0;
}

Measured memory_bytes: 3276
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, m;
vector<int> g[N*3];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    
    for (int i = 0; i < m; i++){
        int u,v;
        cin>>u>>v;
        u--, v--;
        g[u].push_back(v+n);
        g[u+n].push_back(v+2*n);
        g[u+2*n].push_back(v);
    }
    
    int s,t;
    cin>>s>>t;
    s--, t--;
    
    vector<int> d(3*n, -1);
    d[s] = 0;
    queue<int> q;
    q.push(s);
    
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto v: g[u]) {
            if(d[v] == -1){
                d[v] = d[u]+1;
                q.push(v);
            }
        }
    }
    
    if(d[t] == -1)cout<<"-1\n";
    else cout<<d[t]/3<<'\n';
    
    
    
    return 0;
}


Measured memory_bytes: 17792
//#if !defined(YCM) && 1
//#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx")
////#pragma GCC optimize ("O3")
////#pragma GCC target ("sse4")
//#include <stdio.h>
//#endif

#include <bits/stdc++.h>
#include <unistd.h>
//#pragma GCC diagnostic ignored "-Wunused-result"
//#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
#define ll int64_t
#define ull unsigned long long int
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>

#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF (ll)1e18
#define m_p make_pair
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
ll lcm(ll a,ll b){return (a/__gcd(a,b))*b;}
ll bigmod(ll a,ll p,ll mod){ll ans=1;while(p){if(p&1)ans=ans*a%mod;a=a*a%mod;p>>=1;}return ans;}
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0){ll y=power(x,n/2);return y*y;}else return x*power(x,n-1);}

#ifdef shaft
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<endl;
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
const int N=(int)1e6+5;
const int mod=(int)1e9+7;

int main()
{
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(100); cout.tie(nullptr); cin.tie(nullptr);
    #ifdef shaft
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    #endif ///shaft
    int n;

    while(cin >> n){
        int pvx = 0, pvy = 0, pvt = 0;
        int flag = 0;
        int t, x, y;
        for(int i = 0 ; i < n; i++){
            cin >> t >> x >> y;
            int res = abs(x-pvx)+abs(y-pvy);
            ll temp = t-pvt;
            temp -= res;
            if(temp < 0 || temp % 2 )
                flag = 1;
            pvx = x; pvy = y; pvt = t;
        }
        if(flag)
            cout <<"No" << endl;
        else
            cout <<"Yes" << endl;
    }
    return 0;
}





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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

int powint(int b, int e)
{
    int result = 1;
    while (e--) {
        result *= b;
    }
    return result;
}

int main(void)
{
    vector<int> v;
    FOR(l, 3, 9 + 1) {
    REP(i, powint(3, l)) {
        int n = i;
        int x = 0;
        bool has3 = false, has5 = false, has7 = false;
        REP(j, l) {
            x *= 10;
            int r = n % 3;
            if (r == 0) {
                x += 3;
                has3 = true;
            } else if (r == 1) {
                x += 5;
                has5 = true;
            } else if (r == 2) {
                x += 7;
                has7 = true;
            }
            n /= 3;
        }
        if (has3 && has5 && has7) {
            v.pb(x);
        }
    }
    }
    PRINT(v.size());
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    PRINTA(v, 0, 20);

    int N;
    cin >> N;
    int result = upper_bound(all(v), N) - v.begin();
    cout << result << endl;
    return 0;
}



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

typedef long long 			ll;
typedef unsigned long long 	ull;

const int N = 1e5 + 20;

ll a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	ll n, k, sum = 0;
	cin >> n >> k;
	for (int i = 0; i < k; i++)
		cin >> a[i], sum += a[i];
	cout << (sum >= n? "Yes": "No") << endl;
	return 0;
}


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

using namespace std;

#define MOD 1000000007
#define PB push_back

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef pair<int, int> PII;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef set<double> SETD;
typedef multiset<int> MSETI;
typedef deque<int> DQI;
typedef deque<double> DQD;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    VI v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll summ = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            summ += (v[i] * v[j]);
        }
    }
    cout << summ << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int, input().split()))

count = 0

for j in range(0,n):
  for i in range(0,n):
    if a[j]>a[i]:
#      print(j,i)
      if j >= i:
        count += (k-1)*k//2
      else:
        count += k*(k+1)//2
#      print(count)
print(count%(10**9+7))

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

int main(){
	int N,M;
	while(cin >> N >> M&&N&&M){
		vector<int> vi;
		for(int i=1; i<=N; ++i) vi.push_back(i);
		vector<int>::iterator it=vi.begin();
		while(1<vi.size()){
			for(int i=1; it=(it==vi.end()?vi.begin():it),i<M; ++i) ++it;
			it=vi.erase(it); 
		}
		cout << vi[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1228