akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int NIL=-1;

struct Node{
    int p=NIL,l=NIL,r=NIL;
    int depth=0,height=0;
};
void setDepth(Node A[],int n){
    for(int i=0;i<n;i++){
        int d=0,id=i;
        while(A[id].p!=NIL){
            id=A[id].p;
            d++;
        }
        A[i].depth=d;
    }
}
int get_root(Node A[],int n){
    int i=0;
    while(true){
        if(A[i].p==NIL)return i;
        i++;
    }
}
int s_Height(int id,Node A[]){
        int h1=0,h2=0;
        if(A[id].l!=NIL){
            h1=s_Height(A[id].l,A)+1;
        }
        if(A[id].r!=NIL){
            h2=s_Height(A[id].r,A)+1;
        }
        A[id].height=max(h1,h2);
        return max(h1,h2);
}

void setHeight(Node A[],int n){
    int root_id=get_root(A,n);
    s_Height(root_id,A);
}
int count_children(Node A){
    int cnt=0;
    if(A.l!=NIL)cnt++;
    if(A.r!=NIL)cnt++;
    return cnt;
}
int get_sibling(Node A[],int id){
    if(A[id].p==NIL)return -1;
    //親がいる前提
    Node P;P=A[A[id].p];
    if(P.l!=id)return P.l;
    else{return P.r;}
}

int main(){
    int n;cin>>n;Node A[n];
    for(int i=0;i<n;i++){
        int id;cin>>id;
        cin>>A[id].l>>A[id].r;
        //parentの登録
        if(A[id].l!=NIL)A[A[id].l].p=id;
        if(A[id].r!=NIL)A[A[id].r].p=id;
    }
    setDepth(A,n);
    setHeight(A,n);
    for(int i=0;i<n;i++){
        cout<<"node "<<i<<": parent = "<<A[i].p<<", sibling = ";
        if(A[i].p==NIL){
            cout<<-1<<", degree = "<<count_children(A[i])<<", depth = "<<A[i].depth<<", height = "<<A[i].height<<", root"<<endl;;
        }
        else if(A[i].l==NIL && A[i].r==NIL){
            cout<<get_sibling(A,i)<<", degree = "<<0<<", depth = "<<A[i].depth<<", height = "<<0<<", leaf"<<endl;;
        }
        else{
            cout<<get_sibling(A,i)<<", degree = "<<count_children(A[i])<<", depth = "<<A[i].depth<<", height = "<<A[i].height<<", internal node"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3124
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int p[20], c[20];
int d, g;
int ret = 100000000;

bool dfs(int i, int sum, int num, int m) {
    if (i == d) {
        int r = g - sum;
        if (r <= 0) {
            ret = min(num, ret);
            return true;
        } else {
            int point = ((m + 1) * 100);
            if (p[m] >= (r + point - 1) / point) {
                ret = min((r + point - 1) / point + num, ret);
                return true;
            }
        }
        return false;
    }

    dfs(i + 1, sum, num, i);
    dfs(i + 1, sum + c[i] + (i + 1) * 100 * p[i], num + p[i], m);

    return true;
}

int main() {
    scanf("%d%d", &d, &g);
    rep(i, d) scanf("%d%d", &p[i], &c[i]);

    if (dfs(0, 0, 0, 0)) {
        cout << ret;
    } else {
        cout << "error";
    }

    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// C - Sum of product of pairs
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int MOD = (1e9) + 7;
	int64_t ans = 0, b = 0;
	for(int i=0; i<N; ++i){
		int a; cin>>a;
		ans += a * b % MOD;
		ans %= MOD;
		b += a;
		b %= MOD;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int num[10000];
    for(int i=0; i<10000; ++i) num[i] = -1;
    for(int i=2; i<10000; ++i){
        if(num[i]==0) continue;
        num[i] = 1;
        for(int j=i*2; j<10000; j+=i){
            num[j] = 0;
        }
    }
    int prime[10000];
    int index = 0;
    for(int i=2; i<10000; ++i){
        if(num[i]==1){
            prime[index] = i;
            index++;
        }
    }
    
    int N;
    while(cin >> N, N){
        int ans = 0;
        for(int len=1; len<1000; ++len){
            int sum = 0;
            for(int j=0; j<len; ++j){
                sum += prime[j];
            }
            //cout << "len " << len << " sum " << sum << endl;
            if(sum==N){
                ans++;
                continue;
            }
            else if(sum>N){
                break;
            }
            for(int i=0; i+len<10000; ++i){
                sum -= prime[i];
                sum += prime[i+len];
                //cout << "len " << len << " sum " << sum << endl;
                if(sum==N){
                    ans++;
                    continue;
                }
                else if(sum>N){
                    break;
                }

            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1204
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cctype>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int a,b,c,x;
  int ans=0;
  cin>>a>>b>>c>>x;
  for(int q=0;q<=a;q++){
    for(int w=0;w<=b;w++){
      for(int e=0;e<=c;e++){
        if(q*500+w*100+e*50==x){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}


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

bool is_prime(int x) {
    if (x == 2) return true;
    if (x < 2 || x % 2 == 0) return false;
    int i = 3;
    while (i*i <= x) {
        if (x % i == 0) return false;
        i += 2;
    }
    return true;
}

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

    int res = 0;
    for (int i = 0; i < n; i++) {
        if (is_prime(a[i])) res++;
    }

    cout << res << endl;
}


Measured memory_bytes: 3116
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
  int a, b, c, result;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  
  result = min(c, b/a);
  printf("%d", result);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
    long long h;
    long long w;
    cin >> h;
    cin >> w;
    if(h==1||w==1) cout << 1 << endl;
    else cout << (h*w+1)/2 << endl;
}


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

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

	int ans = 0;
	for (int i = 0;i < n - 1;i++) {
		if (a[i] == a[i + 1]) {
			ans++;
			a[i + 1] = -1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
  switch = [0]*n
  j = 0
  while j < n:
    if (i>>j) & 1:
      switch[j] = 1
    j += 1
  light = [0]*m
  for l in range(m):
    for x in range(ks[l][0]):
      if switch[ks[l][x+1]-1] == 1:
        light[l] += 1
  on = 0
  for l in range(m):
    if light[l]%2 != p[l]:
      continue
    on += 1
  if on == m:
    ans += 1

print(ans)        

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  char ans = 'A', a, b;
  while(scanf("%c,%c", &a, &b) != EOF) {
    if(ans == a) ans = b;
    else if(ans == b) ans = a;
  }
  printf("%c\n", ans);
  return 0;
}


Measured memory_bytes: 2664
A, B = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

import math

def is_prime(n):
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

import fractions
x = fractions.gcd(A, B)
divisors = make_divisors(x)
ans = 0
for d in divisors:
    if is_prime(d):
        ans += 1
print(ans)

Measured memory_bytes: 66664
fun main (args : Array<String>) {
	val s = readLine()
	val S : String = s.toString()
	var list : MutableList<String> = mutableListOf()
	var count1 : Int = 1
	var count2 : Int = 1
	for (i in S) {
		list.add(i.toString())
	}
	list.sort()
	if (list[0] == list[1]) {
		count1++
	}
	if (list[2] == list[3]) {
		count2++
	}
	if ( (count1 == 2) && (count2 == 2) ) {
		if (list[0] != list[2]) {
			println("Yes")
		} else {
			println("No")
		}
	} else {
		println("No")
	}
}

Measured memory_bytes: 33648
import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
readString = map BS.unpack . BS.words

getIntList = readIntList <$> BS.getLine
getString = readString <$> BS.getLine
getNString n = map readString <$> replicateM n BS.getLine

getNeibor :: Int -> Int -> Int -> Int -> [[Int]]
getNeibor w' h' w h = do
  let hs
        | h' == 1 = [h', h' + 1]
        | h' == h = [h' - 1, h']
        | otherwise = [h' - 1, h', h' + 1]
  let ws
        | w' == 1 = [w', w' + 1]
        | w' == w = [w' - 1, w']
        | otherwise = [w' - 1, w', w' + 1]
  filter (\x -> x /= [h', w']) (sequence [hs, ws])

sumBomb :: Array (Int, Int) Char -> [[Int]] -> Int
sumBomb sss [] = 0
sumBomb sss (ns : nss)
  | rc == '#' = 1 + sumBomb sss nss
  | otherwise = sumBomb sss nss
  where
    rc = sss ! (head (ns), last (ns))

calc sss h w i = do
  let i' = i + 1
  let h' = i' `div` w
  let w' = i' `mod` w
  let w''
        | w' == 0 = w
        | otherwise = w'
  let h''
        | w' == 0 = h'
        | otherwise = h' + 1
  if sss ! (h'', w'') == '#'
    then putStr "#"
    else do
      let nss = getNeibor w'' h'' w h
      putStr $ show (sumBomb sss nss)
  if w'' == w
    then do
      putStr "\n"
      when (i' /= h * w) $ calc sss h w (i + 1)
    else calc sss h w (i + 1)

calcable :: String -> [Int]
calcable [] = []
calcable (s : ss)
  | s == '#' = 1 : calcable ss
  | otherwise = 0 : calcable ss

calcSingle :: Array Int Int -> Int -> Int -> String
calcSingle ss n' n
  | n' == (n + 1) = []
  | otherwise = v ++ calcSingle ss (n' + 1) n
  where
    v
      | ss ! n' == 1 = "#"
      | n' == 1 = show $ ss ! 2
      | n' == n = show $ ss ! (n - 1)
      | otherwise = show $ (ss ! (n' - 1)) + (ss ! (n' + 1))

putCharLn :: Char -> IO()
putCharLn c = putStrLn $ [c]

main = do
  [h, w] <- getIntList
  if h == 1
    then do
      [sss] <- getString
      if w == 1
        then if sss == "#" then putStrLn "#" else putStrLn "0"
        else do
          let sss' = calcable sss
          let sss'' = listArray (1, w) sss'
          putStrLn $ calcSingle sss'' 1 w
    else do
      if w == 1
        then do
          sss <- getNString h
          let sss' = calcable (concat (map head sss))
          let sss'' = listArray (1, h) sss'
          let result = calcSingle sss'' 1 h
          mapM_ putCharLn result
          putStr "\n"
        else do
          sss <- getNString h
          let sss' = concat (map head sss)
          let sss'' = listArray ((1, 1), (h, w)) sss'
          calc sss'' h w 0


Measured memory_bytes: 1020
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] cost = new int[n];
		for(int i=0;i<n;i++) a[i] = sc.nextInt();
		
		int pos;
		boolean flag = false;
		cost[0] = 1;
		for(int i=1;;i++){
			for(int j=0;j<n;j++){
				if(cost[j]==i && a[j]==0){
					for(int k=1;k<=6;k++){
						pos = j+k;
						while(true){
							if(cost[pos]==0) cost[pos] = i+1;
							else break;
							pos += a[pos];
						}
						if(cost[n-1]>0){
							j = n;
							flag = true;
							break;
						}
					}
				}
			}
			if(flag==true){
				System.out.println(i);
				break;
			}
		}	
	}	
}

Measured memory_bytes: 66292
#include <stdio.h>
 
int main()
{
	int x;
  int y;
  int z;
  int a;
	scanf("%d%d%d", &x, &y, &z);
  
  a = x;
  x = y;
  y = a;
  a = x;
  x = z;
  z = a;
  printf("%d", x);
  printf("%c", ' ');
  printf("%d", y);
  printf("%c", ' ');
  printf("%d", z);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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 long long INF = 1LL << 60;

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1

int main() {
    ull K,X;
    cin >> K >> X;

    if(K*500 >= X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

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

    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front()) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}

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

using namespace std;

int main(){
  vector<bool> v(30);
  for(int i=0;i<28;i++){
    int num;cin>>num;
    v[num-1] = true;
  }
  for(int i=0;i<v.size();i++){
    if(!v[i]) cout<<i+1<<endl;
  }
}


Measured memory_bytes: 3088
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

struct node {
    pi v; int d;
    node(pi v, int d):v(v),d(d){}
    bool operator<(const node &n) const { return d > n.d; }
};
struct edge { pi to; int d; edge(pi ti, int di){to = ti; d = di;} };
map<pi,vector<edge>> G;
map<pi,int> dist; // shortest distance

void dijkstra(pi s) {
    //REP(i,MAX) dist[i] = -1;
    priority_queue<node> que;
    que.push(node(s, 0));
    while(!que.empty()){
        pi v = que.top().v; int d = que.top().d;
        que.pop();
        if(dist.find(v) != dist.end() && dist[v] <= d) continue;
        dist[v] = d;
        for(auto j : G[v])
            que.push(node(j.to, d+j.d));
    }
}

int n,m,p,q,c;

int main(){
    I(n); I(m);
    REP(i,m){
        I(p); I(q); I(c);
        G[mp(p,0)].pb(edge(mp(p,c),1));
        G[mp(q,0)].pb(edge(mp(q,c),1));
        G[mp(p,c)].pb(edge(mp(q,c),0));
        G[mp(q,c)].pb(edge(mp(p,c),0));
        G[mp(p,c)].pb(edge(mp(p,0),0));
        G[mp(q,c)].pb(edge(mp(q,0),0));
    }
    dijkstra(mp(1,0));
    if(dist.find(mp(n,0)) != dist.end()){
        cout << dist[mp(n,0)] << endl;
    } else {
        cout << -1 << endl;
    }
}



Measured memory_bytes: 93488
#include<stdio.h>
int main(void){
    int i,j,k=1,cards[4][14]={0},n,b;
    char a;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf(" %c %d",&a,&b);
        if(a=='S')cards[0][b]=1;
        if(a=='H')cards[1][b]=1;
        if(a=='C')cards[2][b]=1;
        if(a=='D')cards[3][b]=1;
    }
    for(j=0;j<4;j++){
        for(k=1;k<14;k++){
            if(cards[j][k]==0){
                if(j==0)printf("S %d\n",k);
                if(j==1)printf("H %d\n",k);
                if(j==2)printf("C %d\n",k);
                if(j==3)printf("D %d\n",k);
            }
        }
    }
    return 0;
}

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

int main() {
  int64_t X;
  cin >> X;
  int64_t bank = 100;
  int64_t ans = 0;
  while(bank<X){
    bank *= 1.01;
    bank = int64_t(bank);
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    string b;
    cin >> b;
    if(a%2 == 0){
        int aa = a/2;
        string c = b.substr(0,aa);
        string d = b.substr(aa,aa);
        if(c == d){
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
        
    }
    else
    {
        cout << "No" << endl;
    }
    

}

Measured memory_bytes: 256
import bisect
s = list(input())
t = list(input())
from collections import defaultdict
ds = defaultdict(int)  # ｓに含まれる文字それぞれの数
dsl = defaultdict(list)  # ｓの文字の位置
for i in range(len(s)):
    ds[s[i]] += 1
    dsl[s[i]].append(i)


ans = 0
now = -1#ここが-1じゃないと、最初の遷移でsの最初の文字を使えない
for i in range(len(t)):
    if ds[t[i]] == 0:  # ｓにｔを構成する文字がない場合
        print("-1")
        exit()
    elif ds[t[i]] == 1:
        if dsl[t[i]][0] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][0] - now)
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
        now = dsl[t[i]][0]
    else:
        index = bisect.bisect_right(dsl[t[i]], now)
        if index == len(dsl[t[i]]):
            index = -1
        if dsl[t[i]][index] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][index] - now)
            now = dsl[t[i]][index]
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
            now = dsl[t[i]][0]

print(ans)


Measured memory_bytes: 9300
a, b, c, d = map(int, input().split())
#a, b, c, d = 3,4,5,2
if a + b > c + d:
    result = "Left"
elif a + b == c + d:
    result = "Balanced"
elif a + b < c + d:
    result = "Right"
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

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

using namespace std;

int main()
{
  while(1){
    int N,A,B,C,X;
    cin>>N>>A>>B>>C>>X;

    if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0){
      break;
    }

    vector<int> Y;
    for(int i = 0;i < N;++i){
      int temp;
      cin>>temp;
      Y.push_back(temp);
    }

    int X_d;
    int f = 0;
    int s = 0;
    for(int e : Y){
      while(1){
        if(s == 0 && e == X){
          break;
        }
        else{
          if(f == 10000){
            f = -1;
            break;
          }
          else{
            X_d = (A*X + B) % C;
            X = X_d;
            ++f;
          }
        }

        if(X_d == e){
          break;
        }
      }
      if(f == -1){
        break;
      }
      s = 1;
    }

    cout<<f<<endl;
  }
  return 0;
}






Measured memory_bytes: 3144
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	ll n, m;
	cin >> n >> m;
	cout <<abs( (n - 2) * (m - 2)) << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; else return gcd(b, a % b); }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
template <class T> bool amax(T &x, T y) { if (x < y) { x = y; return 1; } else return 0; }
template <class T> bool amin(T &x, T y) { if (x > y) { x = y; return 1; } else return 0; }
template <class T> i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); }
template <class T> i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); }

int main() {
  ioinit();
  int n, k;
  cin >> n >> k;
  vi32 t(n), d(n);
  rep(i, n) cin >> t[i] >> d[i];
  {
    vector<pair<int, int>> p;
    rep(i, n) p.emplace_back(d[i], t[i]);
    rsort(p);
    rep(i, n) d[i] = p[i].first, t[i] = p[i].second;
  }
  i64 sum = 0;
  set<i32> st;
  stack<i32> stk;
  rep(i, k) {
    if (st.count(t[i])) stk.push(d[i]);
    sum += d[i];
    st.insert(t[i]);
  }
  i64 ans = sum + (i64) st.size() * (i64) st.size();
  repi(i, k, n) {
    if (stk.size() == 0) break;
    if (st.count(t[i])) continue;
    st.insert(t[i]);
    sum -= stk.top(); stk.pop();
    sum += d[i];
    amax(ans, sum + (i64) st.size() * (i64) st.size());
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4196
n = int(input())

if n > 100:
    n =  n -  n // 100 * 100
if n > 10:
    n %=10

if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9184
function Puzzle(){
   var obj={};
   var arrA="123,234,345,456,567,678,789,111,222,333,444,555,666,777,888,999".split(",");
   var arrB="11,22,33,44,55,66,77,88,99".split(",");
   var i,j,k,l,m;
   for(i=0;i<16;i++)for(j=0;j<16;j++)for(k=0;k<16;k++)for(l=0;l<16;l++)for(m=0;m<9;m++){
      var str=arrA[i]+arrA[j]+arrA[k]+arrA[l]+arrB[m];
      str=str.split("").map(Number).sort(function(a,b){return a-b;}).join("");
      obj[str]=true;
   }
   return obj;
}
var P=Puzzle();
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   if(Arr.length==0)break;
   var str=Arr.shift();
   var ans=[];
   for(var i=1;i<=9;i++){
      var v=(str+i).split("").map(Number).sort(function(a,b){return a-b;}).join("");
      if(/(.)\1\1\1\1/.test(v))continue;
      if(P.hasOwnProperty(v))ans.push(i);
   }
   console.log((ans.length==0)?"0":ans.join(" "));
}

Measured memory_bytes: 50052
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <bitset>

using ll = long long int;
using ul = unsigned long long int;

// GCD: a > b
ul gcd(ul a,ul b) { return (!b) ? a : gcd(b,a%b); }

int main(int argc,char *argv[])
{
	ll n,m,x;
	std::cin >> n >> m >> x;

	std::vector<ll> c(n,0), a(n*m,0);
	for(ll i = 0;i < n;++i)
	{
		std::cin >> c[i];
		for (ll j = 0;j < m;++j) { std::cin >> a[i*m+j]; }
	}

	ll min = 9999999;
	for(ll i = 0;i < (1<<n);++i)
	{
		ll ans = 0;
		std::bitset<12> s(i);
		std::vector<ll> r(m,0);
		for (ll j = 0;j < n;++j)
		{
			if (s.test(j))
			{
				ans += c[j];
				bool flag = true;
				for (ll k = 0;k < m;++k)
				{
					r[k] += a[j*m+k];
					if (r[k] < x) { flag = false; }
				}
				if (flag) { if (ans < min) { min = ans; } }
			}
		}
	}

	if (min == 9999999) { std::cout << -1 << std::endl; }
	else { std::cout << min << std::endl; }

	return 0;
}

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

using namespace std;

int main()
{

	    
	int n;
	cin>>n;

	vector<int> a(n);
	for(auto &x: a)	cin>>x;

	int max1 = -1;
	int max2 = -1;

	for(int i=0;i<n;i++)
	{
		if(max1 == -1)
		{
			max1 = i;
		}
		else if(a[i]>a[max1])
		{
			max1 = i;
		}
	}

	for(int i=0;i<n;i++)
	{
		if(max2==-1 and max1!=i)
		{
			max2 = i;
		}
		else if(a[i]>a[max2] and i!=max1)
		{
			max2 = i;
		}
	}

	for(int i=0;i<n;i++)
	{
		if(i==max1)
		{
			cout<<a[max2]<<"\n";
		}
		else if(i==max2)
		{
			cout<<a[max1]<<"\n";
		}
		else
		{
			cout<<a[max1]<<"\n";
		}
	}

}

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

int main(){
	int N;
	cin >> N;
	int sn = 0;
	int x = N;
	while (x != 0){
		sn += x%10;
		x /= 10;
	}

	if (N%sn == 0){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,a,b,ans=0;
    cin >> n >> a >> b;
    ll c=a+b;
    ans+=(n/c)*a;
    n=n%c;
    
    n-=a;
    if (n>0){
        ans+=a;
    }else{
        ans+=a;
        ans+=n;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll mod =1e9+7;

void add_self(ll &a, ll b){a+=b;if(a>=mod)a-=mod;}
void sub_self(ll &a, ll b){a-=b;if(a<0)a+=mod;}
void mul_self(ll &a, ll b){a*=b;a%=mod;}
void max_self(ll &a, ll b){if(b>a)a=b;}

ll power(ll a, ll x){ll ret=1;while(x){if(x%2)mul_self(ret,a);x/=2;mul_self(a,a);}return ret;}


const ll N = 305;
double p[N][N][N];

int main()
{
    ios_base::sync_with_stdio(false);
    cout<<setprecision(10)<<fixed;

    ll n,cnt[3]={0};cin>>n;forn(i,n){ll k;cin>>k;k--;cnt[k]++;}

    p[cnt[0]][cnt[1]][cnt[2]]=1;

    forr(c,N)
    {
    	forr(b,N)
    	{
    		forr(a,N)
    		{
    			ll sum = a+b+c;
    			if(sum==0)continue;
    			double pa =(double ) a/sum;
    			double pb =(double ) b/sum;
    			double pc =(double ) c/sum;
    			if(c!=0 && b!=N-1)p[a][b+1][c-1]+=pc*p[a][b][c];
    			if(b!=0 && a!=N-1)p[a+1][b-1][c]+=pb*p[a][b][c];
    			if(a!=0)p[a-1][b][c]  +=pa*p[a][b][c];
    		}
    	}
    }

    double ans =0;
    forr(c,N)forr(b,N)forr(a,N)
    {
		ll good =(a+b+c), total = n;
		if(good != 0) {double waste = (double) total/good; ans += waste*p[a][b][c];}
    }
    //ans+=cnt[0];ans+=cnt[1];ans+=cnt[2];
    cout<<ans<<endl;
}


Measured memory_bytes: 222080
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  cout << 1 - n << endl;
  return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<cmath>

using namespace std;

int main() {
	char c[2][3];

	//入力
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}

	//回転を判定
	for (int i = 0; i < 3; i++) {
		if (c[0][i] != c[1][2 - i]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

}

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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  int cnt = 0;
  for(int i = 0; i < N; i++)cin >> P[i];

  for(int i = 0; i < N - 1; i++){
    if(P[i] == i + 1){
      swap(P[i], P[i + 1]);
      cnt++;
    }
  }
  if(P[N - 1] == N)cnt++;
  // for(auto p : P)cout << p << " ";
  // cout << endl;
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const string U = "U", D = "D", L = "L", R = "R";
    int sx, sy;
    cin >> sx >> sy;
    int tx, ty;
    cin >> tx >> ty;
    string s1,s2,s3,s4;

    FOR(i,sx,tx) {
        s1 += R;
        s2 += L;
    }
    FOR(i,sy,ty) {
        s1 += U;
        s2 += D;
    }
    s3 += D + R + s1 + U + L;
    s4 += U + L + s2 + D + R;

    cout << s1 << s2 << s3 << s4 << endl;
    //cout << s1 << " " << s2 << " " << s3 << " " << s4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong n;
    llong s,t;
    llong cnt=0;
    llong prev = 0;//前に選択した時刻
    cin >> n;
    vector<pair<llong, llong> > Table(n);
    for(int i=0; i<n; i++){
        cin >> s >> t;
        Table[i].first = t;
        Table[i].second = s;
    }

    sort(Table.begin(), Table.end());
    prev = Table[0].first;
    cnt++;
    for(int i=1; i<Table.size(); i++){
        if(prev<Table[i].second){
            cnt++;
            prev = Table[i].first;
        }
    }

    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 4400
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n1 = 0, n2 = 0;
    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0) {
            if (s[i] == '1') n1++;
            else n2++;
        }
        else {
            if (s[i] == '0') n1++;
            else n2++;
        }
    }
    cout << min(n1, n2) << endl;
    return 0;
}


Measured memory_bytes: 512
N=gets.to_i
as=gets.split.map(&:to_i).sort.reverse
total = as.inject(&:+)
count=0
as.each_with_index{|a,i|
    if i==0
        count +=1
        total -= a
        next
    end
    # puts "total=#{total}, as[i-1]=#{as[i-1]}"
    if total * 2 < as[i-1]
        break
    end
    count +=1
    total -= a
}
puts count

  

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

using namespace std;

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

int main() {
	int n, m;
	cin >> n >> m;
	int a[m], b[m],c[m];
	
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}
	
	const int MAX = 999999;
	int dist[n][n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dist[i][j] = MAX;
		}
		dist[i][i] = 0;
	}
	
	for (int i = 0; i < m; i++) {
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
 	}
	
	
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j =0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	
	int ans = 0; 
	for (int i = 0; i < m; i++) {
		if (dist[a[i]][b[i]] < c[i]) {
			ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

void swap(int&x,int&y)
{
  int tmp=x;
  x=y;
  y=tmp;
}

int main()
{
  int x,y;
  cin >> x >> y;
  while(x!=0||y!=0)
    {
      if(x>y)
	swap(x,y);
      cout << x << " " << y << endl;
      cin >> x >> y;
    }

  return 0;
}

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


def solve(x: "List[int]"):
    print(x.index(0)+1)
    return


# Generated by 1.1.7.1 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()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int v, w; };

bool check(string s, string t) {
	int N = s.length(), M = t.length();
	for (int l = 0; l + M <= N; l++) {
		bool ok = true;
		rep(i, M)
			if (s[l + i] == '?' || (s[l + i] == t[i]));
			else ok = false;
		if (ok) return true;
	}
	return false;
}

int main() {
	string s, t; cin >> s >> t;
	if (!check(s, t)) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	int N = s.length();
	rep(i, N) if (s[i] == '?')
		for (char c = 'a'; ; c++) {
			s[i] = c;
			if (check(s, t)) break;
		}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;

    const int M = 4;
    string T = "ACGT";
    map<char, int> dic;
    rep(i, M) dic[T[i]] = i;

    vector<vll> dp(n+1, vll(bit(2*M)));
    dp[0][0] = 1;
    const int mask = bit(2*M) - 1;
    rep(i, n){
        rep(j, bit(2*M)){
            ll cur = dp[i][j];
            if(cur == 0LL) continue;

            rep(k, M){
                int nj = (((j << 2) | k) & mask);

                string S(M, '#');
                rep(l, M){
                    if(i - l >= 0){
                        S[M-l-1] = T[((nj >> (2*l)) & 3)];
                    }
                }
                if(S.substr(1) == "AGC" or 
                   S.substr(1) == "GAC" or
                   S.substr(1) == "ACG" or
                   (S[0] == 'A' and S.substr(2) == "GC") or
                   (S.substr(0, 2) == "AG" and S[3] == 'C')){
                    continue;
                }
                ll& nxt = dp[i+1][nj];
                nxt = ADD(nxt, cur);
            }
        }
    }

    ll res = 0LL;
    for(auto& e : dp[n]){
        res = ADD(res, e);
    }
    cout << res << endl;

    return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int N = s.length();
    string full;
    full = s;
    reverse(full.begin(), full.end());

    string se = "";
    for(int i=0; i<(N-1)/2; i++) {
        se+=s[i];
    }
    string th;
    for(int i=(N+3)/2-1; i<N; i++) {
        th+=s[i];
    }
    string rese;
    string reth;
    rese = se;reth = th;
    reverse(rese.begin(), rese.end());
    reverse(reth.begin(), reth.end());

    if(full != s) {
        cout << "No";
        return 0;
    } else if(rese != se) {
        cout << "No";
        return 0;
    } else if(reth != th) {
        cout << "No";
        return 0;
    } else {
        cout << "Yes";
    }
    return 0;
}


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

int main() {
    int N; cin >> N;
    int arr[101] = {0};
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int d; cin >> d;
        if (!arr[d]) {
            ans++;
            arr[d] = 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main() {
    ll n, p[5] = {};
    
    cin >> n;
    REP(i, n){
        string s;
        cin >> s;
      
      	if(s[0] == 'M'){
            p[0]++;
        }
        else if(s[0] == 'A'){
            p[1]++;
        }
        else if(s[0] == 'R'){
            p[2]++;
        }
        else if(s[0] == 'C'){
            p[3]++;
        }
        else if(s[0] == 'H'){
            p[4]++;
        }
    }
    
    sort(p, p + 5);
    /*
    REP(i, 5){
        cout << p[i] << ' ';
    }
    cout << endl;
    */
  
    ll ans = 0;
    REP(i, 3){
        if(p[i]){
            for(int j = i + 1; j < 4; j++){
                ll t = 0;
                for(int k = j + 1; k < 5; k++){
                    t += p[k];
                }
                ans += p[i] * p[j] * t;
                // cout << p[i] << ' ' << p[j] << ' ' << t << endl;
                // cout << i << ' ' << j << ' ' << endl;
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  string ans="Yes";
  cin>>h>>w;
  char a[h+2][w+2];
  int dx[4]={0,1,0,-1};
  int dy[4]={1,0,-1,0};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i==0||i==h+1||j==0||j==w+1){a[i][j]='.';}
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i+1][j+1];
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      int f=1;
      if(a[i][j]=='.'){continue;}
      for(int k=0;k<4;k++){
        if(a[i+dx[k]][j+dy[k]]=='#'){f=0;}
      }
      if(f){ans="No";break;}
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256