akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Map as Map
import Control.Monad
import Control.Monad.ST
import Data.STRef

main :: IO ()
main = do
  [n, m] <- (map read . words) <$> getLine :: IO [Int]
  (graph, edges) <- buildGraph (Map.fromList [] ) [] m
  print $ length [True | rm <- edges, bfs graph 1 rm < n]

buildGraph graph edges 0 = return (graph, edges)
buildGraph graph edges n = do
  [a, b] <- (map read . words) <$> getLine :: IO [Int]
  let graph' = Map.insertWith (++) a [b] graph
  let graph'' = Map.insertWith (++) b [a] graph'
  buildGraph graph'' ((a, b):edges) (n - 1)

-- あるノードから辿れるノードの総数を求める
bfs :: Map.Map Int [Int] -> Int -> (Int, Int) -> Int
bfs graph start rm = runST $ do
  visitedRef <- newSTRef (Map.fromList [] :: Map.Map Int Bool)
  count <- newSTRef (0 :: Int)
  let queue = [start]
      loop [] = return ()
      loop queue = do
        let p:queue' = queue
        let maybeNeighbors = Map.lookup p graph
        case maybeNeighbors of
          Nothing -> undefined
          Just neighbors ->
            forM_ neighbors $ \n -> do
              visited <- readSTRef visitedRef
              let v = Map.lookup n visited
              case v of
                Just True -> return ()
                Nothing ->
                  if (p == fst rm && n == snd rm) || (p == snd rm && n == fst rm)
                    then return ()
                    else do
                      let visited' = Map.insert n True visited
                      writeSTRef visitedRef visited'
                      modifySTRef count (+1)
                      loop (queue' ++ [n])

  loop queue
  readSTRef count


Measured memory_bytes: 1020
package main

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

// blue > green > red

func main() {
	r, g, b := readInt(), readInt(), readInt()
	k := readInt()

	cnt := 0
	for g <= r {
		g *= 2
		cnt++
	}
	for b <= g {
		b *= 2
		cnt++
	}

	if cnt <= k {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1772
#include<cstdio>
#include<algorithm>
typedef long long ll;
const int MaxN=100010;
int N,V[MaxN],fa[MaxN],siz[MaxN];
ll D[MaxN];
bool cmp(int i,int j){return D[i]<D[j];}
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%lld",D+i),V[i-1]=i;
	std::sort(V,V+N,cmp);
	ll D0=0;
	for(int*i=V+N;--i>V;){
		D0+=siz[*i]++;
		D[*i]-=N-2*siz[*i];
		int*j=std::lower_bound(V,i,*i,cmp);
		if(j<i&&D[*j]==D[*i])siz[fa[*i]=*j]+=siz[*i];
		else return puts("-1"),0;
	}
	if(D0+N-1!=D[*V])return puts("-1"),0;
	for(int*i=V+N;--i>V;)printf("%d %d\n",*i,fa[*i]); 
}

Measured memory_bytes: 3200
#include<cstdio>
#include<algorithm>

#define REP(i,n)   for(int i=0;i<(n);++i)
const int INF = 1e9;

#define MV 100
#define ME 1000
int d[MV][MV],a[ME],b[ME],c[ME];

int main(){
    int v,e,ans=0;
    scanf("%d",&v);
    REP(i,v) REP(j,v) d[i][j] = INF;
    REP(i,v) d[i][i] = 0;
    scanf("%d",&e);
    REP(i,e) scanf("%d%d%d",a+i,b+i,c+i);
    REP(i,e){
        --a[i];--b[i];
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }

    REP(k,v) REP(i,v) REP(j,v) d[i][j] = std::min(d[i][j],d[i][k] + d[k][j]);

    bool used;
    REP(i,e){
        used = true;
        REP(s,v) if(d[s][a[i]] + c[i] == d[s][b[i]]) used = false;
        if(used) ++ans;
    }

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations


def main():
    n, c = map(int, input().split())
    d = [[int(x) for x in input().split()] for _ in range(c)]
    g = [[int(x) - 1 for x in input().split()] for _ in range(n)]
    count = [{}, {}, {}]
    for i in range(n):
        for j in range(n):
            now = g[i][j]
            index = (i + j + 2) % 3
            if now in count[index % 3]:
                count[index % 3][now] += 1
            else:
                count[index % 3][now] = 1
    answer = float("inf")
    for color in permutations([i for i in range(c)], 3):
        now_answer = 0
        for i in range(3):
            for before_color, num in count[i].items():
                now_answer += d[before_color][color[i]] * num
        answer = min(answer, now_answer)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;


__int128 ans = 1;

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int a; string b; cin >> a >> b;
	
	int x = 0;
	
	for(char c : b){
		if(c == '.') continue;
		x *= 10;
		x += (c - '0');
		
	}
	
	cout << a * x / 100;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main(){
  int H,W; cin >> H >> W; vector<string> S(H);
  for(int i = 0; i < H; i++){ cin >> S[i];}
  
  vector<vector<int>> L(H,vector<int>(W));
  vector<vector<int>> R(H,vector<int>(W));
  vector<vector<int>> U(H,vector<int>(W));
  vector<vector<int>> D(H,vector<int>(W));
  
  for(int i = 0; i < H; i++){
    int cnt = 0;
    for(int j = 0; j < W; j++){
      if(S[i][j] == '#'){ cnt = 0;}
      else{ cnt++;}
      L[i][j] = cnt;}
        }
  
  for(int i = 0; i < H; i++){
    int cnt = 0;
    for(int j = W - 1; j >= 0; j--){
      if( S[i][j] == '#'){ cnt = 0;}
      else{ cnt++;}
      R[i][j] = cnt;}
  }
  
  for(int i = 0; i < W; i++){
    int cnt = 0;
    for(int j = 0; j < H; j++){
      if(S[j][i] == '#'){ cnt = 0;}
      else{cnt++;}
      U[j][i] = cnt;}}
  
  for(int i = 0; i < W; i++){
    int cnt = 0;
    for(int j = H - 1; j >= 0; j--){
      if(S[j][i] == '#'){ cnt = 0;}
      else{ cnt++;}
      D[j][i] = cnt;}
  }
  
  int max_sum = 0;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      int c = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3;
    max_sum = max( c,max_sum);}}
  
  cout << max_sum << endl; return 0;}
      

Measured memory_bytes: 69120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename F>
class SegmentTree{
private:
//    using F = function<Monoid(Monoid,Monoid)>;
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    //代入
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    //前計算(?)
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
    template<typename C>
    int find_subtree(int a,const C &check,Monoid &M,bool type) {
        while(a<sz) {
            Monoid nxt = type ? op(seg[2*a+type],M) : op(M,seg[2*a+type]);
            if(check(nxt)) a = 2*a+type;
            else M = nxt, a = 2*a+1-type;
        }
        return a - sz;
    }

    template<typename C>
    int find_first(int a,const C &check) {
        Monoid L = e;
        if(a <= 0) {
            if(check(op(L,seg[1]))) return find_subtree(1,check,L,false);
            return -1;
        }
        int b = sz;
        for(a+=sz,b+=sz;a<b;a>>=1,b>>=1) {
            if(a&1) {
                Monoid nxt = op(L,seg[a]);
                if(check(nxt)) return find_subtree(a,check,L,false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }

    template<typename C>
    int find_last(int b,const C &check) {
        Monoid R = e;
        if(b >= sz) {
            if(check(op(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for(b+=sz; a<b; a>>=1,b>>=1) {
            if(b&1) {
                Monoid nxt = op(seg[--b],R);
                if(check(nxt)) return find_subtree(b,check,R,true);
                R = nxt;
            }
        }
        return -1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    auto op = [](int a,int b){return min(a,b);};
    SegmentTree<int,decltype(op)> 
    seg(N,op,INT_MAX);
    for(int i=0;i<Q;i++){
        int c,x,y;
        cin >> c >> x >> y;
        if(c==0) seg.update(x,y);
        else cout << seg.query(x,y+1) << endl;
    }
}


Measured memory_bytes: 3768
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
ord = [-1] * (n + 1)
s = []
v = 1
c, l = 1, 0
while ord[v] == -1:
    ord[v] = len(s)
    s.append(v)
    v = a[v - 1]
c = len(s) - ord[v]
l  = ord[v]
print(s[k] if k < l else s[l + (k - l) % c])

Measured memory_bytes: 32328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int H;
int W;
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
string Maze[20];

void solve() {
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        cin >> Maze[i];
    }
    int max_l = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (Maze[i][j] == '#') continue;
            queue<pair<int, int>> q;
            q.push(make_pair(i, j));
            int me[H][W];
            memset(me, -1, sizeof(me));
            me[i][j] = 0;
            while(!q.empty()) {
                pair<int, int> p = q.front();
                q.pop();
                for (int k = 0; k < 4; ++k) {
                    int nh = p.first + dx[k];
                    int nw = p.second + dy[k];
                    if (!(nh >= 0 && nh < H && nw >= 0 && nw < W)) continue;
                    if (me[nh][nw] != -1) continue;
                    if (Maze[nh][nw] != '.') continue;
                    int nd = me[p.first][p.second] + 1;
                    q.push(make_pair(nh, nw));
                    me[nh][nw] = nd;
                    if (max_l < nd) max_l = nd;
                }
            }
        }
    }
    cout << max_l << endl;
}

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


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

int main()
{
  int n;
  cin>>n;
  int arr[n],dp[n];
  for(int i=0;i<n;i++)
  {
      cin>>arr[i];
  }
  dp[1]=abs(arr[1]-arr[0]);
  dp[2]=min(abs(arr[2]-arr[0]),abs(arr[1]-arr[0])+abs(arr[2]-arr[1]));
  for(int i=3;i<n;i++)
  {
    int x=abs(arr[i]-arr[i-1]);
    int y=abs(arr[i]-arr[i-2]);
    dp[i]=min(dp[i-1]+x,dp[i-2]+y);
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    aa = [II() for _ in range(n)]
    for a in aa:
        if a%2==1:
            print('first')
            return None
    print('second')
if __name__ == '__main__':
    main()

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  int cnt = 1;
  vector<int> b(0);
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1)) cnt++;
    else {
      b.push_back(cnt);
      cnt = 1;
    }
    if (i == n - 2) b.push_back(cnt);
  }
  sort(b.begin(), b.end());
  int ans = 0;
  if (b.size() > k)
    for (int i = 0; i < b.size() - k; i++) ans += b.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

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

    double ans=0;
    rep(i,n)    ans+=(double)1/a[i];
    ans=(double)1/ans;

    printf("%.9f",ans);

 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n, d[50]={0}, sum=0;
  scanf("%d",&n);
  for(int i=0; i<n; i++){ scanf("%d",&d[i]); }
  
  for(int i=0; i<n; i++){
    for(int j=0; j<i; j++){ sum += (d[i]*d[j]); }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1700
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int W = sc.nextInt();
    int H = sc.nextInt();
    int N = sc.nextInt();
    boolean [][] board = new boolean[W][H];
    int count =0;
    for (int i=0; i<W; i++) {
      for (int j=0; j<H; j++) {
        board[i][j] = false;
      }
    }
    while (sc.hasNext()) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      int a = sc.nextInt();
      switch (a) {
        case 1:
          for(int i=0; i<x; i++) {
            for(int j=0; j<H; j++) {
              board[i][j] = true;
            }
          }
          break; 
        case 2:
          for(int i=x; i<W; i++) {
            for(int j=0; j<H; j++) {
              board[i][j] = true;
            }
          } 
          break;
        case 3:
          for(int i=0; i<W; i++) {
            for(int j=0; j<y; j++) {
              board[i][j] = true;
            }
          } 
          break;
        case 4:
          for(int i=0; i<W; i++) {
            for(int j=y; j<H; j++) {
              board[i][j] = true;
            }
          } 
          break;
        default: break;
      }
    }
    for (int i=0; i<W; i++) {
      for (int j=0; j<H; j++) {
        if (board[i][j] == true) count++;
      }
    }
    System.out.println(W * H - count);
  }
}

Measured memory_bytes: 25432
#include<bits/stdc++.h>
using namespace std;
int main(){
    char X,Y ; cin >> X >> Y;
    vector<char> aaa(6);aaa = {'A' , 'B' , 'C' , 'D' , 'E' , 'F' };
    for(int i = 0; i < 6 ; i++){
        if(X == aaa[i]){
            for(int j = 0; j < 6; j++){
                if(Y == aaa[j]){
                    if(i < j){
                        cout << '<' << endl;
                    }
                    else if(i == j){
                        cout << '=' << endl;
                    }
                    else{
                        cout << '>' << endl;
                    }
                }
            }
        }
    }
    
    return 0;
    }


Measured memory_bytes: 256
c = [[0]*3 for i in range(3)];
for i in range(3) :
	s = input().split(" ");
	for j in range(3) :
		c[i][j] = int(s[j]);
if c[1][0] - c[0][0] == c[1][1] - c[0][1] and c[1][0] - c[0][0] == c[1][2] - c[0][2] and c[2][0] - c[0][0] == c[2][1] - c[0][1] and c[2][2] - c[0][2] == c[2][0] - c[0][0] and c[0][1] - c[0][0] == c[1][1] - c[1][0] and c[0][1] - c[0][0] == c[2][1] - c[2][0] and c[0][2] - c[0][0] == c[1][2] - c[1][0] and c[0][2] - c[0][0] == c[2][2] - c[2][0] :
	print('Yes');
else :
	print('No') 

Measured memory_bytes: 3064
n=int(input())
const=list('abcdefghijklmnopqrstuvwxyz')
res = ''
tmp=n
while 1:
  y = tmp % 26
  res = const[y-1]+res
  tmp = tmp // 26 if y else tmp//26-1
  #print(y,tmp)
  if tmp==0:
    break
print(res)

Measured memory_bytes: 9176
# ARC082D - Derangement (ABC072D)
def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    ans, cur = 0, 0
    for i, j in enumerate(P, 1):
        if i == j:  # subsequence which needs to replace
            cur += 1
        elif i != j and cur:  # replace next to each other
            ans += (cur + 1) // 2
            cur = 0
    ans += (cur + 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct RollingHash{
    static const int MD = 2;
    static const vector<ll> hash_base, hash_mod;

    int n;
    vector<ll> hs[MD], pw[MD];

    RollingHash(){}
    RollingHash(const string &s){
        n = s.size();
        rep(i,MD){
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            rep(j,n){
                pw[i][j+1] = pw[i][j]*hash_base[i] % hash_mod[i];
                hs[i][j+1] = (hs[i][j]*hash_base[i]+s[j]) % hash_mod[i];
            }
        }
    }

    // 1-index
    ll hash_value(int l, int r, int i){
        return ((hs[i][r] - hs[i][l]*pw[i][r-l])%hash_mod[i]+hash_mod[i])%hash_mod[i];
    }

    bool match(int l1, int r1, int l2, int r2){
        bool ret = true;
        rep(i,MD) ret &= (hash_value(l1-1,r1,i) == hash_value(l2-1,r2,i));
        return ret;
    }

    ll calc(int l, int r){
        return (hash_value(l-1,r,0)<<32) | hash_value(l-1,r,1);
    }
};
const vector<ll> RollingHash::hash_base{1009,1021};
const vector<ll> RollingHash::hash_mod{1000000009,1000000007};

const int N = 3000000;

int calc(const string &s, const string &t, int ok){
    int S = s.size(), T = t.size();

    RollingHash hs(s);

    int ng = S/T+1;
    if(ok>0){
        if(ng == ok+1) return ok;
        ng = ok+2;
    }
    // dbg(ng);
    while(ng-ok>1){
        int mid = (ok+ng)/2;

        string tt = "";
        string nt = t;
        rep(i,30){
            if(mid>>i&1) tt += nt;

            nt += nt;
            if(nt.size() > N) break;
        }
        RollingHash ht(tt);

        int TT = T*mid;
        ll tv = ht.calc(1, TT);

        bool valid = false;
        for(int i=1; i+TT-1<=S; ++i){
            if(hs.calc(i,i+TT-1) == tv){
                valid = true;
                break;
            }
        }

        if(valid) ok = mid;
        else ng = mid;
    }
    // dbg(s);dbg(ok);
    return ok;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s,t;
    cin >>s >>t;

    int T = t.size();
    string p = s;
    while(p.size() < 3*T) p += s;
    if(p == s) p += s;
    int x = calc(p,t,0);

    p += p;
    int y = calc(p,t,x);

    int ans = x;
    if(x!=y) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 204004
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define EPS 1e-9
using namespace std;
typedef long long ll;
typedef pair<string, int>P;

int main() {
	int n;
	while (cin >> n, n) {
		vector<int>S, P;
		rep(i, n) {
			int a; scanf("%d", &a);
			S.push_back(a);
		}
		int cnt = 0;
		while (1) {
			rep(i, n) {
				P.push_back(count(S.begin(), S.end(), S[i]));
			}
			if (P == S)break;
			S = P;
			P.clear();
			cnt++;
		}
		cout << cnt << endl;
		rep(i, P.size()) {
			cout << P[i] << (i == P.size() - 1 ? '\n' : ' ');
		}
	}
}

Measured memory_bytes: 3212
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int f=0,sum=0,ans=0;
	char c[]={'A','C','G','T'};
	for(int i=0;i<s.length();i++){
		int flag=0;
		for(int j=0;j<4;j++){
			if(s[i]==c[j]){
				sum++;
				flag=1;
				break;
			}
		}
		if(flag==0){
			//cout<<sum<<endl;
			sum=0;
			f=1;
		}
		if(sum>ans) ans=sum;
	} 
	cout<<ans<<endl;
} 

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

int dp[1001][1001];
int main() {
	int q; scanf("%d", &q);
	rep(i, q) {
		string x, y; cin >> x >> y;
		rep(i, x.size())rep(j, y.size()) {
			if (x[i] == y[j])dp[i + 1][j + 1] = dp[i][j] + 1;
			else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
		}
		printf("%d\n", dp[x.size()][y.size()]);
	}
}

Measured memory_bytes: 7224
#pragma warning (disable:4996)
#include <stdio.h>
#include <ctype.h>

void input(char *str){
	unsigned short int i = 0;
	char ch;
	while (1){
		ch = getchar();
		if (ch == '\n'){
			str[i] = '\0';
			break;
		}
		else {
			str[i] = ch;
			i++;
		}
	}
}
void convert(char *str){
	unsigned short int i;
	for (i = 0; str[i] != '\0'; i++){
		if (islower(str[i]))str[i] = toupper(str[i]);
		else str[i] = tolower(str[i]);
	}
}
void output(char *str){
	unsigned short int i;
	for (i = 0; str[i] != '\0'; i++)printf("%c", str[i]);
	printf("\n");
}
int main(void){
	char str[1200];
	input(str);
	convert(str);
	output(str);
	return 0;
}

Measured memory_bytes: 524
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

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

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	f := make([][]int, n)
	for i := range f {
		f[i] = make([]int, 10)
		for j := range f[i] {
			f[i][j] = readInt()
		}
	}
	p := make([][]int, n)
	for i := range p {
		p[i] = make([]int, 11)
		for j := range p[i] {
			p[i][j] = readInt()
		}
	}

	ans := -10000000000
	for i := 1; i < 1<<10; i++ {
		o := make([]int, 10)
		for j := range o {
			if b := 1 << uint(j); i&b == b {
				o[j] = 1
			} else {
				o[j] = 0
			}
		}

		sum := 0
		for fi := range f {
			cnt := 0
			for fj := range f[fi] {
				if f[fi][fj] == o[fj] {
					cnt += o[fj]
				}
			}
			sum += p[fi][cnt]
		}
		ans = max(ans, sum)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int totalVote = 0, M;
int check(int vote)
{

    if((vote * 4 * M ) < totalVote )
       return 0;
    else
        return 1;
}
int main()
{

    int N;

    cin >> N >> M;
    int eligibleCount = 0;
    int vote[1003];
    int i;
    for(i = 0; i < N; i++)
    {
        cin >> vote[i];
        totalVote += vote[i];



    }
    for(i = 0; i < N; i++)
        eligibleCount += check(vote[i]);

    if(eligibleCount >= M && M <= N)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

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

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int ans = 0;
	int x; cin >> x;
	int k = x / 500;
	x %= 500;
	ans += k * 1000;
	ans += x - (x % 5);
	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    suma = 0
    sumb = 0
    fixL = sorted(a, reverse=True)
    for i in range(N):
        if i % 2 == 0:
            suma += fixL[i]
        else:
            sumb += fixL[i]
    print(suma - sumb)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;
 
signed main(void){
    string s;
    cin>>s;
    rep(i,s.size())cout<<"x";
    cout<<endl;
   
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;

ll n, k, c, a[200010];

ll modpow(ll x, ll e) {
  ll res = 1;
  while (e > 0) {
    if (e & 1) res = res * x % MOD;
    x = x * x % MOD;
    e >>= 1;
  }
  return res;
}


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

  ll ans = k;
  a[k] = 1;
  for (ll i = k - 1; i > 0; --i) {
    a[i] = modpow(k / i, n);
    for (ll j = i * 2; j <= k; j += i) {
      a[i] = (a[i] - a[j] + MOD) % MOD;
    }
    ans = (ans + a[i] * i % MOD) % MOD;
  }
  cout << ans;
  return 0;
}



Measured memory_bytes: 4380
#python3

def f(num):
    if num % 3 == 0:
        return True
    if num % 5 == 0:
        return True
    return False

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    e = [i for i in a if i%2 == 0]
    flag = True

    for i in e:
        if f(i):
            pass
        else:
            flag = False

    if flag:
        print('APPROVED') 
    else:
        print('DENIED') 
main()


Measured memory_bytes: 3060
#include<stdio.h>

int main (void){

  int k,x,s;
  int i;
  int b[100];
 
  
	s=scanf("%d %d" ,&k, &x);
  
  	if(s!=2) return -1;
  
  	if(k==1) printf("%d ",x );
     else{
	
    //b[0]= x-k+1;
      
  	/*for(i=1;i<2*k-1;i++){
    	     b[i]=b[i-1]+1;
    }*/
  
	for(i=x-k+1;i<=x+k-1;i++){
    	
      printf("%d ", i);
    
    }
     }
	return 0;
}

Measured memory_bytes: 128
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
  int a, b;
  std::cin >> a >> b;
  std::cout << (a * (a - 1)/2 + (b * (b - 1) /2)) << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

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);
        int n = in.nextInt();
        double[] coin = new double[n];
        for (int i = 0; i < n; i++) {
            coin[i] = in.nextDouble();
        }
        double[][] d = new double[n][n + 1];
        d[0][1] = coin[0];
        d[0][0] = 1 - coin[0];
        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= n; j++) {
                d[i][j] = d[i - 1][j] * (1 - coin[i]);
                if (j - 1 >= 0) {
                    d[i][j] += d[i - 1][j - 1] * coin[i];
                }
            }
        }

        double ans = 0;
        for (int i = 0; i <= n; i++) {
            if (i > n / 2)
                ans += d[n - 1][i];
        }
        out.println(ans);
        out.close();
    }

    private static void dfs(Vertex v, Set<Vertex> visited, Stack<Vertex> st) {
        visited.add(v);
        for (Vertex n : v.adj) {
            if (!visited.contains(n))
                dfs(n, visited, st);
        }
        st.add(v);
    }

    static class Vertex {
        int i;

        public Vertex(int i) {
            this.i = i;
        }

        List<Vertex> adj = new ArrayList<>();
    }

    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 int nextInt() {
            return Integer.parseInt(next());
        }

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

    }
}


Measured memory_bytes: 130768
#pragma region default
#include<bits/stdc++.h>

//iteration
#define rep(i,m) for(int i=0;i<(m);++i)
#define rev(i,m) for(int i=(int)(m) - 1;i>=0;--i)
#define repn(i) for(int i = 0; i < n; ++i)
#define revn(i) for(int i=(int)(n) - 1;i>=0;--i)

//IO
#define newline() cout<<'\n'
#define line(s) cout<<(s)<<'\n'
#define spaced(s) cout<<(s)<<' '
#define rint(n) int n;cin>>n

#define all(x) (x).begin(),(x).end()
#define sqr(x) ((x)*(x))
#define present(c,x) ((c).find(x) != (c).end()) 

#define long long long

using namespace std;

//constants
const int inf = 1234567890;
const long infl = 8876543210123456789ll;
const int MOD = 1000000007;

void init() {
	ios::sync_with_stdio(false);
	cin.tie(0);
}

template <class RandomAccessIterator>
void print(RandomAccessIterator a, RandomAccessIterator b) {
	for (; a < b; ++a) {
		line(*a);
	}
}

template <class RandomAccessIterator>
void println(RandomAccessIterator a, RandomAccessIterator b) {
	for (; a < b; ++a) {
		spaced(*a);
	}
	newline();
}

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#pragma endregion

int a[100];

int main() {
	init();
	string s;
	cin >> s;
	if (s.length() == 2 && s[0] == s[1]) {
		cout << "1 2";
		return 0;
	}
	for (size_t i = 2; i < s.length(); i++) {
		if (s[i] == s[i - 1] || s[i] == s[i - 2]) { cout << i - 1 << " " << i + 1;
		return 0;
		}
	}
	cout << "-1 -1";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];
  queue<P> q;
  Graph d(h, V(w,-1));
  rep(i,h) rep(j,w) {
    if (grid[i][j] == '#') {
      d[i][j] = 0;
      q.push(make_pair(i,j));
    }
  }
  ll ans = 0;
  vector dy = {0,1,0,-1};
  vector dx = {1,0,-1,0};
  while (!q.empty()) {
    ll y = q.front().first, x = q.front().second;
    rep(i,4) {
      ll ny = y+dy[i], nx = x+dx[i];
      if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if (d[ny][nx] == -1 && grid[ny][nx] == '.') {
        d[ny][nx] = d[y][x]+1;
        q.push(make_pair(ny,nx));
        ans = max(d[ny][nx],ans);
      }
    }
    q.pop();
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 28388
import sys
readline = sys.stdin.readline

N = int(readline())
T, A = map(int,readline().split())

for i in range(N - 1):
  t,a = map(int,readline().split())
  n = max((T + t - 1)//t,(A + a - 1)//a)
  T,A = n*t,n*a
  
print(T + A)

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
    int n, row, col;
    scanf("%d", &row);
    scanf("%d", &col);
    scanf("%d", &n);
    
    int temp;
    int count = 0;

    if (row > col) {
        temp = row;
    } else {
        temp = col;
    }

    for (int i = 0; i < n; i = i + temp) {
        count++;
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <stack>
#include <cstdlib>

int main(int argc,char* argv[]){
  
  std::stack<int> stack;
  std::string input;

  while(std::cin >> input){
    if(input == "+"){
      int post = stack.top(); stack.pop();
      int pre = stack.top();  stack.pop();
      
      stack.push(pre + post);
    }else if(input == "-"){
      int post = stack.top(); stack.pop();
      int pre = stack.top();  stack.pop();
      
      stack.push(pre - post);
    }else if(input == "*"){
      int post = stack.top(); stack.pop();
      int pre = stack.top();  stack.pop();
      
      stack.push(pre * post);
    }else{
      stack.push(std::atoi(input.c_str()));
    }
  }
  
  std::cout << stack.top() << std::endl;

  return 0;
  
}

Measured memory_bytes: 1200
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
P = LIST()

total = 0
com = N + 1
for i in range(N):
	com = min(com, P[i])
	if P[i] == com:
		total += 1
print(total)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	long long n;
	t = 1;
	while(t--) {
	 cin >> n;
	 if(n % 2)
	  cout << 2 * n << endl;
	 else
	  cout << n << endl;
	}
	return 0;
}



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

struct edge{
	int to;
	long long cost;
};

int N,Q,K;
vector<edge> G[100010];
vector<long long> dist(100010);
vector<long long> ans;
queue<int> que;
vector<bool> visited(100010,false);

void BFS(){
	while(que.empty()==0){
		int f=que.front();
		que.pop();
		for(auto t:G[f]){
			if(!visited[t.to]){
				dist[t.to]=dist[f]+t.cost;
				visited[t.to]=true;
				que.push(t.to);
			}
		}
	}
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N-1;i++){
		int a,b;
		long long c;
		scanf("%d%d%lld",&a,&b,&c);
		edge e;e.to=b;e.cost=c;
		G[a].push_back(e);
		e.to=a;
		G[b].push_back(e);
	}
	
	scanf("%d%d",&Q,&K);
	
	dist[K]=0;
	que.push(K);
	visited[K]=true;
	
	BFS();
	
	for(int i=0;i<Q;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		long long a=dist[x]+dist[y];
		ans.push_back(a);
	}
	
	for(auto a:ans)printf("%lld\n",a);
	return 0;
}

Measured memory_bytes: 11120
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
        x: usize,
        y: usize,
    }

    let mut ans: Vec<usize> = Vec::new();
    ans.push(a*x+b*y);
    let more = max(x,y);
    let less = min(x,y);
    for i in 1..more+1 {
        if i<=less {
            ans.push(ans[i-1]-(a+b)+2*c);
        } else {
            if x>=y {
                ans.push(ans[i-1]-a+2*c);
            } else {
                ans.push(ans[i-1]-b+2*c);
            }
        }
        // debug!(ans);
    }

    ans.sort();
    println!("{}", ans[0]);

}


Measured memory_bytes: 2884
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;

int main(){
	string x;
	cin >> x;
	vector<char> str(200001);
	int ind = 0;
	for(char c : x){
		if(ind && str[ind - 1] == 'S' && c == 'T'){
			ind--;
		}else{
			str[ind++] = c;
		}
	}
	cout << ind << endl;
	return 0;
}



Measured memory_bytes: 1336
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k = 0;
  int t = s.length();
  for (int i = 0; i < t / 2; i++) {
    if (s[i] != s[t - i - 1]) {
      k++;
    }
  }
  cout << k << endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

void solve()
{
    string S; cin >> S;
    vb alphabet(26, false);
    REP(i, S.length()) alphabet[S[i]-'a'] = true;
    REP(i, 26)
    {
        if(alphabet[i] == false)
        {
            cout << char('a'+i) << endl;
            return;
        }
    }
    cout << "None" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,l;
  while(cin>>n>>l,n){
    vector<Int> s(n),t(n),u(n);
    for(Int i=0;i<n;i++) cin>>s[i]>>t[i]>>u[i];
    using D = double;
    auto check=
      [&](D x)->Int{
        D cap=l;
        vector<D> res(2);
        for(Int k=0;k<2;k++){
          Int lst=0;
          for(Int i=0;i<n;i++){
            cap+=x*D(s[i]-lst);
            chmin(cap,l);
            cap+=D(x-u[i])*D(t[i]-s[i]);
            if(cap<0) return 0;
            lst=t[i];
          }          
          cap+=x*D(86400-lst);
          chmin(cap,l);
          if(cap==l) return 1;
          res[k]=cap;
        }
        return res[0]<=res[1];
      };    
  
    D L=0,R=1e9;
    for(Int k=0;k<100;k++){
      D M=(L+R)/2;
      if(check(M)) R=M;
      else L=M;
    }
    cout<<R<<endl;
  }
  return 0;  
}



Measured memory_bytes: 5072
# -*- coding: utf-8 -*-
"""
B - Sum of Three Integers
https://atcoder.jp/contests/abc051/tasks/abc051_b

"""
import sys


def solve(K, S):
    ans = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if 0 <= z <= K:
                ans += 1
            elif z < 0:
                break
    return ans


def main(args):
    K, S = map(int, input().split())
    ans = solve(K, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
k,n = gets.split.map(&:to_i)
an = gets.split.map(&:to_i)
#an.push(k)
bn = Array.new

(an.length-1).times{ |i|
    bn.push(an[i+1]-an[i])
}
bn.push( k-an[-1]+an[0]  )
#------------------------------------
c=n-1
total=0
#最初の距離を計算
c.times{|t|
    total += bn[t]
}
now_len = total
#---------------------------
j = bn.length-1
for num in 1..j do
    if num+c-1 > j then
        out = num+c-(bn.length+1)
        now_len = now_len-bn[num-1]+bn[out]
    else
        now_len = now_len-bn[num-1]+bn[num+c-1]
    end

    if total > now_len then
        total = now_len
    end
end
p total

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

using namespace std;

int main () {
    string s = "", t = "";
    cin >> s >> t;
    vector<bool> changed(26, false);
    for (int i=0; i<s.size(); i++) {
        if (s.at(i) == t.at(i)) changed.at(s.at(i) - 'a') = true;
        else {
            if (!changed.at(s.at(i) - 'a') && !changed.at(t.at(i) - 'a')) {
                changed.at(t.at(i) - 'a') = true;
                char buf = s.at(i);
                for (int j=0; j<s.size(); j++) {
                    if (s.at(j) == buf) s.at(j) = t.at(i);
                    else if (s.at(j) == t.at(i)) s.at(j) = buf;
                }
            }
            else {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;    
}


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

int main(){
  int s;
  int n[2];
  
  cin >> s;
  n[1] = s/100;
  n[0] = (s-n[1]*100);
  if(1<=n[1]&&n[1]<=12)
    if(1<=n[0]&&n[0]<=12)
      cout << "AMBIGUOUS";
    else
      cout << "MMYY";
  else
    if(1<=n[0]&&n[0]<=12)
      cout << "YYMM";
    else
      cout << "NA";
return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<cctype>
#include<string>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF 2100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
int dp[4545][4545],mxc[4545],a[4545],b[4545],c[4545];
int main(void)
{
	int d,n,sa,mx;
	cin>>d>>n;
	rep(i,0,d) cin>>mxc[i];
	rep(i,0,n) cin>>a[i]>>b[i]>>c[i];
	rep(i,0,d)rep(j,0,n) dp[i][j]=0;
	rep(i,0,d) {
		rep(j,0,n) {
			if(a[j]<=mxc[i]&&mxc[i]<=b[j]) {
				rep(k,0,n) {
					if(a[k]<=mxc[i+1]&&mxc[i+1]<=b[k]) {
						sa=abs(c[j]-c[k]);
						dp[i+1][k]=max(dp[i][j]+sa,dp[i+1][k]);
					}
				}
			}
		}
	}
	rep(i,0,n) mx=max(mx,dp[d-1][i]);
	cout<<mx<<endl;
	return 0;
}
		
	

Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int k;
  cin >> k;
  cout << ((k+1)/2)*(k/2) << endl;
}


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

int main(){
    long long n;
    cin >> n;
    int sum = 0;
    int t = n;
    while(t > 0){
        sum += t % 10;
        t /= 10;
    }

    cout << (n % sum == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

index = 0
for i in itertools.permutations(range(1,n+1)):
 if p == i:
  a = index
 if q == i:
  b = index
 index += 1

print(abs(a-b))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
    int N;
    long long cnt=0;
    cin>>N;
    V<long long> A(N+1),B(N);
    rep(i,N+1)cin>>A[i];
    rep(i,N)cin>>B[i];

    rep(i,N){
        if(A[i]<=B[i]){
            cnt+=A[i];
            B[i]-=A[i];
            A[i]=0;

            if(A[i+1]<=B[i]){
                cnt+=A[i+1];
                B[i]-=A[i+1];
                A[i+1]=0;
            }
            else{
                A[i+1]-=B[i];
                cnt+=B[i];
                B[i]=0;
            }
        }
        else{
            A[i]-=B[i];
            cnt+=B[i];
            B[i]=0;
        }
    }
    cout<<cnt<<endl;
    return 0;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> gr(n, vector<int>());
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    gr.at(a).push_back(b);
    gr.at(b).push_back(a);
  }
  vector<int> ans(n, -1);
  queue<int> q;
  q.push(0);
  ans.at(0) = 0;
  int co = 1;
  while(!q.empty()){
    int now = q.front(); q.pop();
    for(auto i : gr.at(now)){
      if(ans.at(i) != -1) continue;
      ans.at(i) = now+1;
      co++;
      q.push(i);
    }
  }
  if(co != n){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
    rep2(i, 1, n){
      cout << ans.at(i) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 10116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}
int main()
{
	int H,W,N,i,j,k,x,y;
	string S,T;
	cin >> H >> W >> N;
	cin >> y >> x;
	cin >> S;
	cin >> T;
	int l = 0;
	int u = 0;
	int r = W+1;
	int d = H+1;
	for(i = N-1; i >=0; --i)
	{
		if(T[i] == 'L')
		{
			if(r != W+1)
			{
				r ++;
			}
		}
		else if(T[i] == 'R')
		{
			if(l != 0)
			{
				l --;
			}
		}
		else if(T[i] == 'U')
		{
			if(d != H+1)
			{
				d ++;
			}
		}
		else if(T[i] == 'D')
		{
			if(u != 0)
			{
				u --;
			}
		}
		if(S[i] == 'L')
			l ++;
		if(S[i] == 'R')
			r --;
		if(S[i] == 'U')
			u ++;
		if(S[i] == 'D')
			d --;
		if(r-l<=1 || d-u<=1)
		{
			break;
		}
	}
	if(x>=r || x<=l || y>=d || y <= u)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;

	return 0;
}









Measured memory_bytes: 776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        boolean flg = false;

        for (int a = A; a<=B; a++) {
            if (a % K == 0) {
                flg = true;
            }
        }

        if (flg) {
            System.out.println("OK");
        } else {
            System.out.println("NG");
        }
    }
}

Measured memory_bytes: 35724
#include<stdio.h>
int main(){
	int a,b;
		scanf("%d %d",&a,&b);
		if(a<b){
			printf("a < b\n");
		}
				else if(a==b) {
					printf("a == b\n");
				}
	else{
		printf("a > b\n");
	}

 return 0;
}

Measured memory_bytes: 2596
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m=map(int,input().split())
ans=0
if n>1:
    ans+=combinations_count(n, 2)
if m>1:
    ans+=combinations_count(m, 2)
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var S = Console.ReadLine().Split();
		Console.WriteLine(S.Distinct().Count() == 3 ? "Three" : "Four");
	}
}

Measured memory_bytes: 13280