akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts, BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

run [] = (0, 0)
run ([a,b]:tl) = let (s, t) = run tl
                     (sd, td) | a < b = (0, 3)
                              | a > b = (3, 0)
                              | otherwise = (1, 1)
                 in (s + sd, t + td)

main = do
    n <- readInt
    (s, t) <- run <$> replicateM n (words <$> getLine)
    putStrLn $ show s ++ " " ++ show t


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n, m, s, t;
    cin >> n >> m;
    vector<vector<int>> a(m, vector<int>());
    int u, v;
    if (m == 0) {
        cout << -1 << endl;
        return 0;
    }
    REP(i, m){
        cin >> u >> v;
        u--;
        v--;
        a[u].push_back(v);
    }
    cin >> s >> t;
    s--;
    t--;

    deque<pair<int, ll>> q;
    set<pair<int, ll>> memo;
    q.emplace_back(s, 0);
    memo.emplace(s, 0);

    ll c;
    while (!q.empty()) {
        tie(u, c) = q.front(); q.pop_front();

        if (u == t && c % 3 == 0) {
            cout << c / 3 << endl;
            return 0;
        }

        for (auto w : a[u]) {
            if (memo.count(make_pair(w, (c + 1) % 3)) == 0) {
                q.emplace_back(w, c + 1);
                memo.emplace(w, (c + 1) % 3);
            }
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 24576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll ans,n,m,a[N],mod[N];
map<ll,ll> mp;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(ll i=0;i<n;i++)cin>>a[i],mod[a[i]%m]++,mp[a[i]]++;
    ans=mod[0]/2;
    mod[0]%=2;
    if(m%2==0)ans+=mod[m/2]/2,mod[m/2]%=2;
    for(ll i=1;i<m;i++){
        if(2*i==m)continue;
        ll have = min(mod[i] , mod[m-i]);
        ans+=have;
        mod[i]-=have;
        mod[m-i]-=have;
    }
    for(ll i=0;i<n;i++){
        ll have = min(mod[a[i]%m] , mp[a[i]])/2;
        if(have){
            ans+=have;
            mod[a[i]%m]-=2*have;
            mp[a[i]]-=2*have;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static final int MOD = 1_000_000_007;

  public static void main(String[] args) {
    int N = sc.nextInt();
    long A = sc.nextLong();
    long B = sc.nextLong();
    if (A > B) {
      long t = A;
      A = B;
      B = t;
    }
    long[] S = new long[N + 1];
    S[0] = -1_000_000_000_000_000_001L;
    for (int i = 0; i < N; i++) {
      S[i + 1] = Long.parseLong(sc.next());
      if (i > 0 && S[i + 1] < S[i - 1] + A) {
        System.out.println(0);
        return;
      }
    }
    long[][] dp = new long[2][N + 1];
    dp[0][1] = 1;
    dp[1][0] = dp[1][1] = 1;
    long[] bsum = new long[N + 2];
    bsum[1] = 1;
    bsum[2] = 2;
    int limit = 0;
    int prev = 0;
    for (int i = 2; i <= N; i++) {
      while (S[prev + 1] <= S[i] - B) {
        ++prev;
      }
      if (S[i] < S[i - 1] + A) {
        dp[0][i] = dp[1][i - 1];
        dp[1][i] = prev < limit ? 0 : (bsum[prev + 1] - bsum[limit] + MOD) % MOD;
        limit = i - 1;
      } else {
        dp[0][i] = (dp[0][i - 1] + dp[1][i - 1]) % MOD;
        dp[1][i] = prev < limit ? 0 : (bsum[prev + 1] - bsum[limit] + MOD) % MOD;
      }
      bsum[i + 1] = (bsum[i] + dp[1][i]) % MOD;
    }
    long ans = (dp[0][N] + dp[1][N]) % MOD;
    System.out.println(ans);
  }

}


Measured memory_bytes: 33088
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
 
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}

int find(vec &v,int l,int r,int i){
   
    int ans = -1;
    while(l<=r){
        int mid=(l+r)/2;
        if(v[mid]>=i){
            ans = mid;
           r = mid - 1;
            
        }
        else{
            l = mid + 1;
        }
    }
    return ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y, a, b, c;
   
    cin >> x >> y >> a >> b >> c;
    vec va(a), vb(b), vc(c);
   
    fo(i,a)
    cin>>va[i];
    fo(i, b)
            cin >>
        vb[i];
    fo(i, c)
            cin >>
        vc[i];
    so(va);
    so(vb);
    so(vc);
    int in1 = a - x,in2=b-y;

    int val = x + y;
    int i1 = a - 1, i2 = b - 1, i3 = c - 1;
    int ans = 0;
    while(val--){
        int v1, v2, v3;
        if(i1<in1)
            v1 = -1e5;
        else
        {
            v1 = va[i1];
        }
        if(i2<in2)
            v2 = -1e5;
        else
        {
            v2 = vb[i2];
        }
        if(i3<0)
            v3 = -1e5;
        else
        {
            v3 = vc[i3];
        }
        int ma1 = max(max(v1, v2), v3);
        ans += ma1;
        if(v1==ma1)
            i1--;
        else if(v2==ma1)
            i2--;
        else
            i3--;

    }

    cout << ans;
} 

Measured memory_bytes: 2560
def is_square_num(n):
  a = 0
  for i in range(0, n+1):
    if a == n:
      return True
    if a > n:
      return False
    a += i * 2 + 1

a, b = map(str, input().split())
val = int(a+b)
if is_square_num(val):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
inline void read(long long &x)
{
	x=0;
	long long p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
long long n,m;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);read(m);
	if(n>m)swap(n,m);
	if(n==1&&m==1)return cout<<1<<endl,0;
	if(n==1)return cout<<(m-2)<<endl,0;
	long long ans=(n-2ll)*(m-2ll);
	cout<<ans<<endl;
	return 0;
}

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}

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

const int INF = 1e18;

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

  int n;
  cin >> n;
  int d=n%10;
  if (d == 2 || d == 4 || d == 5 || d== 7 || d == 9)
    cout << "hon\n";
  else if (d == 0 || d == 1 || d == 6 || d == 8)
    cout << "pon\n";
  else
    cout << "bon\n";
}


Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>W(N);
	rep(i, N) {
		cin >> W[i];
	}
	vector<int>S(N);
	S[0] = W[0];
	for (int i = 1; i<N; i++) {
		S[i] = S[i - 1] + W[i];
	}
	int sum = S[N - 1];
	int ans = 1000000000;
	rep(i, N) {
		ans = min(ans, abs(2 * S[i] - sum));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int[] a = new int[N + 1];
			for(int i = 1; i < a.length; i++) {
				a[i] = in.nextInt();
			}
			int tmp   = 1;
			int count = 0;
			while(count < N) {
				tmp = a[tmp];
				count++;
				if(tmp == 2) {
					break;
				}
			}
			if(count == N) {
				count = -1;
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

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

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

	}
}


Measured memory_bytes: 35272
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin>>N>>M;
  int nAC = 0, nWA = 0;
  vector<bool> isAC(N, false);
  vector<int> WAcount(N, 0);
  int p; string S;
  for(int i=0; i<M; i++){
    cin>>p>>S;
    p--;
    if(S=="AC"){
      if(!isAC[p]){
        isAC[p] = true;
        nAC++;
        nWA += WAcount[p];
      }
    }else if(S=="WA"){
      if(!isAC[p]){
        WAcount[p]++;
      }
    }
  }
  cout<<nAC<<" "<<nWA<<endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void){
    int n;
    int count = 0;
    bool eq;
    int ans = 0;
    cin >> n;
    int num[n+1]; bool check[n];
    num[n] = 2000000000;
    for(int i = 0; i < n; i++)
        cin >> num[i];
    
    for(int i = 0; i < n; i++){
       if(num[i] >= num[i+1])
        count++;
        if(num[i] < num[i+1]){
            ans = max(ans, count);
            count = 0;
        }
    }

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

Measured memory_bytes: 640
#include <iostream>
#include <stack>
using namespace std;
int main()
{
  string X;
  cin >> X;
  stack<char> st;
  int N = X.length();
  for (int i = 0; i < N; i++)
  {
    if (X[i] == 'S')
      st.push(X[i]);
    else
    {
      if (0 < st.size() && st.top() == 'S')
        st.pop();
      else
        st.push(X[i]);
    }
  }
  cout << st.size() << endl;
  return 0;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int s;
  cin >> s;
  vector<int> m(1000001);
  int cnt = 0;
  while (true) {
    cnt++;
    m[s]++;
    if (m[s] == 2) {
      cout << cnt << endl;
      return 0;
    }
    if (s % 2 == 0)
      s /= 2;
    else
      s = 3 * s + 1;
  }
}


Measured memory_bytes: 7144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>inline bool read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c)){if(c==EOF)return false;f^=c=='-',c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
    return true;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10^48);
}
template<class T>inline void print(T x,char c){print(x),putchar(c);}
template<class T,class ...S>inline bool read(T &x,S &...y){return read(x)&&read(y...);}
int ans;
char s[100];
int main(){
	scanf("%s",s);
	if (s[0]==s[1]&&s[0]==s[2]&&s[0]=='R') ans=3;
	else if (s[0]==s[1]&&s[0]=='R') ans=2;
	else if (s[1]==s[2]&&s[1]=='R') ans=2;
	else if (s[0]=='R'||s[1]=='R'||s[2]=='R') ans=1;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;
    dsu d(n);
    while(q--) {
        ll t, a, b;
        cin >> t >> a >> b;
        if(t)
            cout << d.same(a, b) << endl;
        else
            d.merge(a, b);
    }
}

Measured memory_bytes: 3920
using System;

class L
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

		var dp = new long[n, n];
		for (int i = 0; i < n; i++) dp[i, i] = a[i];

		for (int i = 1; i < n; i++)
			for (int l = 0; l + i < n; l++)
				dp[l, l + i] = Math.Max(a[l] - dp[l + 1, l + i], a[l + i] - dp[l, l + i - 1]);
		Console.WriteLine(dp[0, n - 1]);
	}
}


Measured memory_bytes: 83552
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	K := sc.NextInt()
	fmt.Println(N - K + 1)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  bool S[H][W];
  REP(h,H)REP(w,W){
    char c;
    cin>>c;
    if(c=='#')S[h][w]=false;
    else S[h][w]=true;
  }
  int ans=0;
  REP(h,H)REP(w,W){
    if(!S[h][w])continue;
    auto s=make_pair(h,w);
    queue<pair<int,int> > q;
    q.push(s);
    int d_max=0;
    int d[H][W];
    REP(i,H)REP(j,W)d[i][j]=-1;
    d[s.first][s.second]=0;
    while(!q.empty()){
      auto p=q.front();
      q.pop();
      vector<pair<int,int> > v;
      if(p.first>0)v.push_back(make_pair(p.first-1,p.second));
      if(p.first<H-1)v.push_back(make_pair(p.first+1,p.second));
      if(p.second>0)v.push_back(make_pair(p.first,p.second-1));
      if(p.second<W-1)v.push_back(make_pair(p.first,p.second+1));
      for(auto e:v){
        if(S[e.first][e.second] and d[e.first][e.second]<0){
          q.push(e);
          d[e.first][e.second]=d[p.first][p.second]+1;
          d_max=max(d_max,d[e.first][e.second]);
        }
      }
    }
    // cerr<<h<<" "<<w<<" "<<d_max<<endl;
    ans=max(ans,d_max);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <string.h>

int main(){
	int dice[6];
	char p[101];
	int i;
	
	for(i = 0;i < 6;i++)
		scanf("%d",&dice[i]);
	
	scanf("%s",p);
	
	for(i = 0;i < strlen(p);i++){
		int tmp = dice[0];
		switch(p[i]){
			case 'W':
				dice[0] = dice[2];dice[2] = dice[5];dice[5] = dice[3];dice[3] = tmp;
			break;
			case 'E':
				dice[0] = dice[3];dice[3] = dice[5];dice[5] = dice[2];dice[2] = tmp;
			break;
			case 'S':
				dice[0] = dice[4];dice[4] = dice[5];dice[5] = dice[1];dice[1] = tmp;
			break;
			case 'N':
				dice[0] = dice[1];dice[1] = dice[5];dice[5] = dice[4];dice[4] = tmp;
			break;
		}
	}
	
	printf("%d\n",dice[0]);
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void){
    int n,m,i,j,total,max,s[1000];
    while(1){
        total=0;
        max=0;
        scanf("%d",&n);
        scanf("%d",&m);
        if(n==0){
            break;
        }
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
        }
        for(i=0;i<n;i++){
            total=s[i];
            for(j=i+1;j<n;j++){
                if((max<total + s[j])&&(total+s[j]<=m)){
                    max=total+s[j];
                }
            }
        }
        if(max!=0){
            printf("%d\n",max);
        }else{
            printf("NONE\n");
        }
    }
    return 0;
    
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int CalcLCS(string X, string Y){
  int c[1001][1001];
  int m = SZ(X);
  int n = SZ(Y);
  REP1(i,m) c[i][0]=0;
  REP1(j,n) c[0][j]=0;

  REP0(i,m){
    REP0(j,n){
      if (X[i]==Y[j]) {
        c[i+1][j+1] = c[i][j] + 1;
      } else {
        c[i+1][j+1] = max(c[i][j+1], c[i+1][j]);
      }
    }
  }
  return c[m][n];
}


int main(int argc, char const *argv[]) {
  int q; std::cin >> q;
  string X,Y;

  REP0(i,q){
    std::cin >> X >> Y;
    std::cout << CalcLCS(X,Y) << '\n';
  }

  return 0;
}



Measured memory_bytes: 6956
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    ll r = 0;
    for (int i = 0; i < n; i++) {
        r += (ll)c[i] * (n - 1 - i + 2) % P;
    }
    r %= P;

    for (int i = 0; i < n + (n - 1) - 1; i++) {
        r = r * 2 % P;
    }
    cout << r << endl;

    //最後に2^Nを掛ければいいとして
    //戦略としてはコストが低いものから貪欲に
    //各C_iについて平均何番目かわかれば

    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, Q = lr()
S = sr()
lr_list = []
for i in range(Q):
    l, r = lr()
    lr_list.append((l, r))

cnt = 0
ac_list = [0]
for i, (s1, s2) in enumerate(zip(S, S[1:])):
    if s1 + s2 == 'AC':
        cnt += 1
        ac_list.append(cnt)
    else:
        ac_list.append(cnt)

for (l, r) in lr_list:
    print(ac_list[r - 1] - ac_list[l - 1])


Measured memory_bytes: 19812
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def solution():
    k = int(input())
    nums = []
    for i in range(1, k+1):
        for j in range(1, k+1):
            for l in range(1, k+1):
                if i == j == l:
                    nums.append(i)
                else:
                    nums.append(gcd(i,j,l))
    print(sum(nums))

solution()


Measured memory_bytes: 189608
#include <iostream>

using namespace std;
int r, g, b;

int main(void) {
	int ans = 0;
	cin >> r >> g >> b;
	ans = r * 100 + g * 10 + b;
	if (ans % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable.{Map => MMap}
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val S = in.next
  val Mod = 1000000007

  val NA = 0
  val A = 1
  val AB = 2
  val ABC = 3

  val ar = Array.fill(4)(0L)
  ar(NA) = 1

  def dp(l: List[Char]): Long = l match {
    case Nil => ar(ABC)
    case x :: xs => x match {
      case 'A' => ar(A) = (ar(A) + ar(NA)) % Mod
      case 'B' => ar(AB) = (ar(AB) + ar(A)) % Mod
      case 'C' => ar(ABC) = (ar(ABC) + ar(AB)) % Mod
      case _ =>
        ar(ABC) = (ar(ABC) * 3 + ar(AB)) % Mod
        ar(AB) = (ar(AB) * 3 + ar(A)) % Mod
        ar(A) = (ar(A) * 3 + ar(NA)) % Mod
        ar(NA) = (ar(NA) * 3) % Mod
      }
      dp(xs)
  }

  println(dp(S.toList))
}

Measured memory_bytes: 31700
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N, M = LI()
A = [LI() for _ in range(N)]
m = [[0] * 3 for _ in range(8)]

for c in range(4):
  A.sort(key=lambda x:(((c>>2)&1)*2-1)*x[0]+(((c>>1)&1)*2-1)*(-1)*x[1]+((c&1)*2-1)*x[2])
  for i in range(M):
  	for j in range(3):
  		m[c*2][j] += A[i][j]
  		m[c*2+1][j] += A[N-1-i][j]

print(max([abs(x[0])+abs(x[1])+abs(x[2]) for x in m]))


Measured memory_bytes: 3360
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  sort(a);
  ll ans = n, sum = 0, i = 0;
  while (i < n) {
    // debug3(i, a[i], sum);
    sum += a[i];
    bool ok = true;
    for (int j = i + 1; j < n; j++) {
      if (a[j] <= sum * 2) {
        sum += a[j];
      } else {
        ans -= j - i;
        i = j;
        ok = false;
        break;
      }
    }
    if (ok) break;
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1656
#include<cstdio>
char s[100010];
int main()
{
	int n;
	scanf("%d",&n);
	if(n==0){
		printf("0");
		return 0;
	}
	scanf("%s",s+1);
	char bef=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]!=bef){
			ans++;
		}
		bef=s[i];
	}
	printf("%d",ans);
	return 0;
}

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

int n;

struct node{
	vector<vector<long long>> v;
	node()
	{
		v.resize(n,vector<long long> (n));
	}
	
	node operator*(node ob1)
	{
		vector<vector<long long>> tmp(n,vector<long long> (n));
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				for(int k=0;k<n;k++)
				{
					tmp[i][j]+=v[i][k]*ob1.v[k][j];
					tmp[i][j]%=MOD;
				}
			}
		}
		
		node ob=node();
		ob.v=tmp;
		
		return ob;
	}
};

main()
{
	long long k;
	cin>>n>>k;
	
	vector<vector<long long>> adj(n,vector<long long> (n));
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		cin>>adj[i][j];
	}
	
	node ans=node();
	ans.v=adj;
	
	node tmp=node();
	vector<vector<long long>> v(n,vector<long long> (n));
		
	for(int i=0;i<n;i++)
	v[i][i]=1;
	
	tmp.v=v;
	
	while(k>0)
	{
		
		
		if(k%2)
		tmp=tmp*ans;
		
		ans=ans*ans;
		//ans=ans*tmp;
		
		k/=2;
	}
	
	long long cnt=0;
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		cnt=(cnt+tmp.v[i][j])%MOD;
	}
	
	cout<<cnt;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)

	taste := 0
	for i := 0; i < n; i++ {
		taste += l + i
	}

	fmt.Println(taste - minimal_Absolute_Value(n, l))

}

func minimal_Absolute_Value(n, l int) int {
	if l <= 0 {
		if l+n <= 0 {
			return l + n - 1
		} else {
			return 0
		}
	} else {
		return l
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	int d,t,s;
	scanf("%d%d%d",&d,&t,&s);
	if(s*t>=d)
        printf("Yes\n");
    else
        printf("No\n");
	return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    map<ll, ll> mp;
    rep(i, n){
        if(mp[a.at(i)]==0) mp[a.at(i)]++;
        else mp[a.at(i)]--;
    }

    int cnt = 0;
    for(auto x: mp){
        if(x.second!=0) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int r;
    cin >> r;

    cout << 3 * pow(r,2.0) << endl;
}


Measured memory_bytes: 256
/*input
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn];

int main()
{
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	int mx=*max_element(a,a+n);
	int cnt=0;
	REP(i,n) if(a[i]<mx-1){
		cout<<"No\n";
		return 0;
	}
	REP(i,n) if(a[i]==mx-1) cnt++;
	if(mx==n-1&&cnt==0){
		cout<<"Yes\n";
		return 0;
	}
	if(mx<=cnt) cout<<"No\n";
	else if(cnt+2*(mx-cnt)<=n) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int n; cin>>n;
    double ans=0;
    rep(i, n){
        double u; 
        string x;
        cin>>u;
        cin>>x;
        if(x=="JPY"){
            ans += u;
        } else {
            ans +=(u*380000.0);
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 3e3 + 9;
const ll mod = 998244353;
typedef pair<ll,ll> LL;

ll a,b,n,m,dp[N][N];
ll f(ll i,ll j){
    if (i > n||j > m) return 0;
    if (i == n&&j == m) return 1;
    if (dp[i][j] != -1) return dp[i][j];
    ll ans = (i*f(i,j + 1) + j*f(i + 1,j) - i*j*f(i + 1,j + 1) + mod*mod)%mod;
    return dp[i][j] = ans%mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>a>>b>>n>>m;
    memset(dp,-1,sizeof(dp));
    cout<<f(a,b);
}


Measured memory_bytes: 74772
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A(sc);
	}
	
	public static void A(Scanner sc) {
		int N = sc.nextInt();
		int A = sc.nextInt();
		if(N%500 <=A) out.println("Yes");
		else out.println("No");
	}
}


Measured memory_bytes: 22608
#include <stdio.h>
#include <string.h>

int main(){
    char c;

    scanf("%c", &c);

    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') puts("vowel");
    else puts("consonant");

    return 0;
}

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

using namespace std;

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

	string s; cin >> s;

	if(s.size() < 26){
		map<char,bool> mp;
		for (int i = 0;i < s.size();i++){
			mp[s[i]] = true;
		}
		for (int i = 0;i < 26;i++){
			if(!mp['a'+i]){
				cout << s << char('a'+i) << endl;
				return 0;
			}
		}
	}

	for (int i = s.size()-1;i > 0;i--){
		if(s[i] > s[i-1]){
			map<char,bool> mp;
			for (int j = 0;j < i;j++){
				mp[s[j]] = true;
			}
			for (int j = 0;j < 26;j++){
				if(!mp['a'+j] && 'a'+j > s[i-1]){
					cout << s.substr(0,i-1) << char('a'+j) << endl;
					return 0;
				}
			}
		}
	}

	cout << -1 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a <= b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

//int cnt = 1;

void rec(vector<vector<int>>& path, int l,int r,int cnt) {//[l,r)
	if (r-l <= 1)return;
	int t = r - l;
	int m = (r + l + 1) / 2;
	FOR(i, l, m) {
		FOR(j, m, r) {
			path[i][j] = cnt;
			path[j][i] = cnt;
		}
	}
	//cnt++;
	rec(path, l, m, cnt+1);
	rec(path, m, r,cnt+1);
}

int main() {
    IOS;
	int n;
	cin >> n;
	vector<vector<int>> path(n, vector<int>(n, 0));
	rec(path, 0, n,1);
	REP(i, n-1) {
		FOR(j,i+1,n) {
			cout << path[i][j] << " ";
		}
		put("");
	}
	return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main(void){
	int n,m;
	int i,j;
	char str1[20000];
	char str2[100000];
	while(scanf(" %d",&n)){
		if(n == 0){
			break;
		}
	for(i = 0;i < n * 2;i++){
		scanf(" %c",&str1[i]);
	}
	scanf("%d",&m);
	for(i = 0;i < m;i++){
		scanf(" %c",&str2[i]);
	}
	i = 0;
	while(str2[i] != '\0'){
		for(j = 0;j < n * 2;j = j + 2){
			if(str2[i] == str1[j]){
				str2[i] = str1[j+1];
				break;
			}
		}
		i++;
	}
	str2[i] = '\0';
	for(i = 0;i < m;i++){
		printf("%c",str2[i]);
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 676
#include <stdio.h>
#define N 100
int main(){
  int i,j,k=0,n,tmp;
  int A[N];
  scanf("%d",&n);
  for(j=0;j<=n-1;j++){
    scanf("%d",&A[j]);
  }
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	tmp=A[j-1];
	A[j-1]=A[j];
	A[j]=tmp;
	k++;
      }
    }
  }
  for(j=0;j<=n-1;j++){   
    printf("%d",A[j]);
    if(j<n-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",k);
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;

mat mul(mat &A,mat &B){
  mat C(A.size(),vec(B[0].size()));
  for(int i=0;i<A.size();i++)
    for(int k=0;k<B.size();k++)
      for(int j=0;j<B[0].size();j++)
	C[i][j]+=A[i][k]*B[k][j];

  return C;
} 

mat pow(mat A,int n){
  mat B(A.size(),vec(A.size()));
  for(int i=0;i<A.size();i++)B[i][i]=1;
  for(;n>0;n>>=1){
    if(n&1)B=mul(B,A);
    A=mul(A,A);
  }
  return B;
}

int main(void){
  int n,m,z,s,d;

  while(cin >> n >> m >> z,n|m|z){
    vector<P>G;
    G.push_back(P(1,1));
    for(int i=0;i<m;i++){
      cin >> s >> d;
      G.push_back(P(s,d));
      G.push_back(P(d,s));
    }
    mat A(G.size(),vec(G.size()));
 
    for(int i=0;i<G.size();i++)
      for(int j=1;j<G.size();j++)
	if(i!=j && G[i].first!=G[j].second)
	  A[i][j]=G[i].second==G[j].first;

    A=pow(A,z);

    bool fg=false;
    for(int i=0;i<A.size();i++)
      if(G[i].second==n && A[0][i])fg=true;

    cout << (fg?"yes":"no") << endl;
  }
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	if(n < 4){
		cout << "No" << endl;
		return 0;
	}
	for(int i=0;n >= 0;i++){
		if(n%4 == 0){
			cout << "Yes" << endl;
			return 0;
		}
		n -= 7;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
N,M = map(int,input().split())
G = {}
for _ in range(M):
    A,B = map(int,input().split())
    if A not in G:
        G[A] = []
    G[A].append(B)
    if B not in G:
        G[B] = []
    G[B].append(A)
color = [-1 for _ in range(N+1)]
que = deque([1])
color[1] = 0
flag = 0
while que:
    cur = que.popleft()
    for x in G[cur]:
        if color[x]<0:
            color[x] = (color[cur]+1)%2
            que.append(x)
        else:
            if color[x]==(color[cur]+1)%2:continue
            else:
                flag=1
                break
    if flag==1:break
if flag==0:
    n = color.count(0)
    m = color.count(1)
    cnt = n*m-M
else:
    cnt = (N*(N-1))//2-M
print(cnt)

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

using namespace std;

int N;
string S;
int dp[500001];

int sz[500001]; // 1 が何個連続しているか

int main()
{
  cin >> N;
  cin >> S;

  for(int i = 0; i < S.size(); i++) {
    if(S[i] == '1') {

      // 1111101 型
      if(i > 0 && S[i - 1] == '0') {
        for(int j = i - 2; j >= 0; j--) {
          if(S[j] == '0') break;
          dp[i + 1] = max(dp[i + 1], dp[j] + (i - 1) - j);
        }
      }

      // 1011111 型
      if(i + 1 < N && S[i + 1] == '0') {
        for(int j = i + 2; j < N; j++) {
          if(S[j] == '0') break;
          dp[j + 1] = max(dp[j + 1], dp[i] + j - (i + 1));
        }
      }

    }

    dp[i + 1] = max(dp[i], dp[i + 1]);
  }

  cout << dp[S.size()] << endl;
}

Measured memory_bytes: 2820
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> count(m + 1);
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int a;
            cin >> a;
            count[a]++;
        }
    }

    int ans = 0;
    for (const int e : count) {
        if (e == n) {
            ans++;
        }
    }

    cout << ans << "\n";

    return 0;
}

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

int main() {
    int a, b; cin >> a >> b;
    int n; cin >> n;
    bool ans = false;
    for(int i = 0; i < n; ++i) {
        int s, f; cin >> s >> f;
        ans |= (a <= s && s < b) || (s <= a && a < f);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
const int maxn= 3010;
char s[maxn];
char t[maxn];
int len1,len2;
int dp[maxn][maxn];
bool vis[maxn];

int main() {
	cin>>s>>t;
	
	
	int len1 = strlen(s), len2 = strlen(t);
	for(int i=1;i<=len1;i++)
	for(int j=1;j<=len2;j++)
		if (s[i - 1] == t[j - 1]) {
			dp[i][j] = dp[i - 1][j - 1] + 1;
		}
		else
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
	
	int i = len1, j = len2;
	while (i && j) {
		if (s[i - 1] == t[j - 1]) {
			vis[i-1]=1;
			i--;
			j--;
		}
		else {
			if (dp[i][j] == dp[i - 1][j]) i--;
			else j--;
		}
	}
	
		int flag=0;
	
	for(int i=0;i<len1;i++)
	{
		if(vis[i]) 
		{
			flag=1;
			cout<<s[i];
		}
	}
	
	if(flag==0)
	cout<<" ";
	return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}

int a, n, k, t, t2, b1, b2, b3;

signed main() {
	int p, q, r;
	cin >> p >> q >> r;
	cout << min(p + q, min(p + r, q + r)) << endl;;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int max = 0;
  int sum = 0;
  
  cin >> n;
  
  for ( int i = 0 ; i < n ; i++) {
  	int a;
    cin >> a;
    
    sum += a;
    if (a >= max) max = a;
  }
  cout << sum - (max/2) << endl;
  
  
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    for (var i = 0; i < 10000; i++) {
        var num = parseInt(input[i]);
         if (num == 0) {
            break;
        }
        console.log("Case " + ( i + 1) + ": " + num)

           }

    
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug() {
    var input = document.getElementById("input").value;
    Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22380
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include <utility>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<functional>
#include<algorithm>
#define ms0(a) memset(a,0,sizeof(a))
#define ms1(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
using namespace std;
typedef long long  ll;
//typedef __int64  ll;
const double Eps = (double)0.5;
const int M = 1e9 + 7;
const int N = 1e5 + 5;
const double PI = acos(-1.0);
char a[N];
int main()
{
    int k;
    cin>>a>>k;
    int l = strlen(a);
    for(int i=0; i<l; i++)
    {
        if(a[i] != 'a')
        {
            int of = (int)'z' - a[i];
            if(k > of)
            {
                a[i] = 'a';
                k -= of+1;
            }
        }
    }
    k = k%26;
    a[l-1] += k;
    cout << a << endl;
}


Measured memory_bytes: 384