akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N, D, M;
    string C, O;

    cin >> N;
    vector<pair<int,string>> v; // (density, color)
    for (int i=0; i<N; ++i) {
        cin >> C >> D;
        v.emplace_back(D, C);
    }
    sort(v.begin(), v.end());
    cin >> M;
    
    int k = 0;
    bool ok = true;
    for (int i=0; i<M; ++i) {
        cin >> O;
        while (k < N && v[k].second != O) k ++;
        if (k >= N) ok = false;
        else {
            while (k+1 < N && v[k].first == v[k+1].first) k ++;
            k ++;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 12396
Scanf.scanf "%d %s %s" (fun n s1 s2 ->
    let ( *@) a b = (a * b) mod 1_000_000_007 in
    let rec loop i prev acc =
        if i = n then acc else
            match prev, s1.[i] = s2.[i] with
            | true,  true  -> loop (i + 1) true  (acc *@ 2)
            | true,  false -> loop (i + 2) false (acc *@ 2)
            | false, true  -> loop (i + 1) true   acc
            | false, false -> loop (i + 2) false (acc *@ 3)
    in
    Printf.printf "%d\n" @@
        if s1.[0] = s2.[0] then loop 1 true 3
                           else loop 2 false 6
)

Measured memory_bytes: 3820
import static java.lang.System.out;
import java.io.File;
import static java.lang.Integer.parseInt;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().debt();
    }

    public void debt() {
        try (Scanner scan = new Scanner(System.in)) {
            debtHell(scan);
        } catch (Exception e) {
            System.exit(0);
        }
    }

    public void debt(String inputDataPath) {
        try (Scanner scan = new Scanner(new File(inputDataPath))) {
            debtHell(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void debtHell(Scanner scan) {
        double debt = 100000;
        int week = parseInt(scan.nextLine());
        for (int i = 0; i < week; i++)
            debt = rateCalc(debt);
        out.println((int) debt);
    }

    private double rateCalc(double debt) {
        debt *= 1.05;
        return (debt % 1000 > 0) ? debt + 1000 - debt % 1000 : debt;
    }
}

Measured memory_bytes: 26016
N = int(input())
T,A = map(int, input().split())
H = list(map(int, input().split()))
min_dif = 10**9
for i in range(N):
    dif = abs(A-(T-H[i]*0.006))
    if min_dif > dif:
        min_dif = dif
        res_i = i
print(res_i+1)

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

int main(){
  int N, K; cin >> N >> K;
  int64_t ans=K;
  if(N==1){
    cout << ans << endl;
    return 0;
  }
  for(int i=1;i<=N-1;i++){
    ans*=K-1;
  }
  cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a < b)	printf("<\n");
	else if(a > b)	printf(">\n");
	else printf("=\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll mod;
ll n;
ll comb[3010][3010]={};
ll dp[3010]={};
ll dp2[3010][3010]={};
long long ruijo(long long  k,long long m,long long p){
	if(m==0)return (ll)1;
	if(m==1)return k%p;
	long long s = ruijo(k,m/2,p);
	if(m%2==0){
		return (s*s)%p;
	}else{
		long long ans;
		ans = (s*s)%p;
		return (k*ans)%p;
	}
}

int main(){
    cin >> n >> mod;
    rep(i,3010){
        comb[i][i] = 1;
        comb[i][0] = 1;
    }

    for(int i=1;i<3010;i++){
        for(int j= 1;j<=i;j++){
            comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%mod;
        }
    }
    rep(i,3010){
        dp2[i][0] = 1;
    }
    for(ll i=1;i<3010;i++){
        for(ll j=1;j<=i;j++){
            dp2[i][j] = (dp2[i-1][j-1] + (j+1) * dp2[i-1][j] ) %mod;
        }
    }
    ll w[3010]={};
    rep(i,3010){
        w[i] = ruijo(2,ruijo(2,i,mod-1),mod);
    }
    
    for(ll i=0;i<=n;i++){
        ll tmp = 0;
        for(ll j=0;j<=i;j++){
            ll tmp2 = (dp2[i][j]*ruijo((ll)2,j*(n-i),mod))%mod;
            tmp2 = (tmp2*w[n-i])%mod;
            tmp = (tmp+tmp2)%mod;
        }
        dp[i] = (comb[n][i] * tmp)%mod;
        
    }
   
    ll ans = w[n];
    for(int i=1;i<=n;i++){
        if(i%2==1){
            ans = (ans +mod - dp[i])%mod;
        }else{
            ans = (ans + dp[i])%mod;
        }
        
    }
    cout <<ans << endl;
    return 0;
}

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

vector<string> vl;
int n; 
int m;

void dfs(string s){
    if(s.size() > m) return;
    set<char> tmp;
    for(char c : s) tmp.insert(c);
    if(tmp.size() == 3) vl.push_back(s);
    for(char a : "357"){
        if(a=='\0') continue;
        dfs(s+a);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    m = toString(n).size();
    if(n<357){
        cout<<0<<endl;
        return 0;
    }

    dfs("");
    int ans = 0;
    for(auto a : vl){
    //        cout<<a<<endl;
    if(stoi(a)<=n) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1660
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  Printf.printf "\n";
  preorder (fun e -> print_string " "; print_int e) t;
  Printf.printf "\n"

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let delete x t =
  let rec balance = function
    | Nil -> assert false
    | Node (x, Nil, r) -> (x, r)
    | Node (x, l, r) ->
      let (m, l) = balance l in
      (m, Node (x, l, r)) in
  let rec doit = function
    | Nil -> assert false
    | Node (y, l, r) ->
      if x = y then
        if l = Nil then r
        else if r = Nil then l
        else
          let (m, r) = balance r in
          Node (m, l, r)
      else if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | ["delete"; n] -> t := delete (int_of_string n) !t
    | _ -> print !t
  done

Measured memory_bytes: 27184
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

const int INF = 1LL << 60;

signed main(){

  int n,m; cin >> n >> m;
  vector<int> a(m),b(m);
  vector<int> c(m);
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    int res = 0;
    for(int j = 0; j < b[i]; j++){
      int cost; cin >> cost;
      cost--;
      res += 1 << cost;
    }
    c[i] = res;
  }

  static int dp[1002][(1<<12)+1];
  fill(dp[0],dp[1001]+(1<<12),INF);
  dp[0][0] = 0;
  for(int i = 0; i < m; i++){
    for(int k = 0; k < 1<<n; k++){
      dp[i+1][k] = min(dp[i+1][k],dp[i][k]);
      dp[i+1][k|c[i]] = min(dp[i+1][k|c[i]],dp[i][k|c[i]]);
      if(dp[i][k] >= INF) continue;
      dp[i+1][k|c[i]] = min(dp[i+1][k|c[i]],dp[i][k] + a[i]);
    }
    // for(int k = (1<<n)-1; k >= 0; k--){
    //   dp[i+1][k] = min(dp[i+1][k],dp[i][k]);
    //   if(dp[i][k] >= INF) continue;
    //   //cout << a[i] << " " << dp[i][k] << " " << dp[i][k]+a[i] << endl;
    //   dp[i+1][k|c[i]] = min(dp[i+1][k|c[i]],dp[i][k] + a[i]);
    // }
  }
  int ans = dp[m][(1<<n)-1];
  if(ans >= INF) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    vector<int> vec;
    int n;
    in(n);
    int q,x;
    while(n--){
        in(q);
        if(q==0){
            in(x);
            vec.push_back(x);
        }else if(q==1){
            in(x);
            out(vec[x]);
        }else if(q==2){
            vec.pop_back();
        }
    }
}


Measured memory_bytes: 3860
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e9);
const int mod = 998244353; // check modulo

int dp[3030][3030], a[3030];

void solve() {
    int n, s; cin >> n >> s;
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        for(int j = 0; j <= s; ++j) {
            if (j - a[i] >= 0) dp[i][j] = (dp[i - 1][j - a[i]] + dp[i][j]) % mod;
            dp[i][j] = (dp[i][j] + dp[i -  1][j] * 2) % mod;
        }
    }
    cout << dp[n][s];
}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("elevator.in", "r", stdin);
//    freopen("elevator.out", "w", stdout);
//    int test; cin >> test;
//    for(int t = 1; t <= test; ++t) {
        solve();
//    }
    return 0;
}


Measured memory_bytes: 74164
#include <stdio.h>

int isprime(int n);

int main(void)
{
	int i,n,prime1,prime2;

	while(scanf("%d",&n)!=EOF){
		for(i=n-1; !(prime1=isprime(i)); i--)
			;
		for(i=n+1; !(prime2=isprime(i)); i++)
			;
		printf("%d %d\n",prime1,prime2);
	}

	return 0;
}

int isprime(int n)
{
	int i;

	if(n<2)
		return 0;
	else if(n==2)
		return n;
	for(i=2; i<=n/2; i++)
		if(n%i==0)
			return 0;
	
	return n;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    int a,b,c,ans=0,s=0;
    cin>>a>>b>>c;
    while(s<c){
        s=s+a;
        ans++;
        if(ans%7==0)s=s+b;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3116
n=int(input())
s=list(input())
ans=0
for i in range(10):
    if str(i) in s:
        first=s.index(str(i))
        for j in range(10):
            if str(j) in s[first+1:]:
                second=first+1+s[first+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[second+1:]:
                        ans+=1
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int n,k,x,y;
cin >> n >> k >> x >> y;

int ans = 0;
if(n < k) ans = n*x;
else {
    ans += k*x;
    ans += (n-k)*y;
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        while(n!=0){
            String[] list = new String[n];
            for(int i=0; i<n; i++) list[i] = sc.next();

            int[] cnt = new int[26];
            int INF = Integer.MAX_VALUE/10;
            int[][] dist = new int[26][26];
            for(int i=0; i<26; i++) Arrays.fill(dist[i], INF);
            for(int i=0; i<n; i++){
                char first = list[i].charAt(0);
                char last = list[i].charAt(list[i].length()-1);
                dist[first-'a'][last-'a'] = 1;
                cnt[first-'a']++; cnt[last-'a']--;
            }
            /*
            boolean boo = true;
            int odd = 0;
            for(int i=0; i<26; i++){
                int cnt = 0;
                for(int j=0; j<26; j++){
                    if(dist[i][j]==1) cnt++;
                    if(dist[j][i]==1) cnt++;
                }
                if(cnt%2==1) odd++;
            }
            if(odd>2) boo = false;
            boo = boo & bfs(dist, list[0].charAt(0)-'a');
            */
            boolean boo = bfs(dist, list[0].charAt(0)-'a');
            for(int i=0; i<26; i++){
                if(cnt[i]!=0) boo = false;
            }
            if(boo) System.out.println("OK");
            else System.out.println("NG");
            n = sc.nextInt();
        }
    }

    boolean bfs(int[][] dist, int sidx){
        LinkedList<Integer> list = new LinkedList<Integer>();
        boolean[] v = new boolean[dist.length];
        list.add(new Integer(sidx));

        while(list.size()>0){
            int pos = list.poll();

            if(v[pos]) continue;
            v[pos] = true;

            for(int i=0; i<dist.length; i++){
                if(dist[pos][i]==1){
                    list.add(new Integer(i));
                    dist[pos][i] = 0;
                }
            }
        }

        for(int i=0; i<dist.length; i++){
            for(int j=0; j<dist[0].length; j++){
                if(dist[i][j]==1) return false;
            }
        }
        return true;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 47308
//#include <bits/stdc++.h>
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using T = tuple<int, int, int>;
constexpr int INF = 1e9+7;
list<T> ls;
int H, W, h, w, d, eh, ew, dist[1005][1005], dhw[][2] = {{0,1},{0,-1},{1,0},{-1,0}};
char s[1005];
int main(){
	scanf("%d%d%d%d%d%d", &H, &W, &h, &w, &eh, &ew);
	h++; w++; eh++; ew++;
	fill(dist[0], dist[1004], -1);
	rep(i,H){
		scanf("\n%s", s);
		rep(j,W) if(s[j] == '.') dist[i+2][j+2] = INF;
	}
	ls.emplace_front(h,w,0);
	while(!ls.empty()){
		tie(h,w,d) = ls.front(); ls.pop_front();
		if(dist[h][w] <= d) continue;
		dist[h][w] = d;
		for(auto [dh, dw]: dhw) if(dist[dh+=h][dw+=w] == INF) ls.emplace_front(dh, dw, d);
		rep(i,5) rep(j,5) if(dist[h+i-2][w+j-2] == INF) ls.emplace_back(h+i-2,w+j-2,d+1);
	}
	printf("%d\n", dist[eh][ew] == INF ? -1 : dist[eh][ew]);
}

Measured memory_bytes: 10684
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }



int main() {
    int n;
    cin >> n;
    vector<double>v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    double ans = 0.0;
    for(int i = 1;i<n;i++) {
        v[i] = (v[i]+v[i-1])/2;
        ans = v[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println("" + c + " " + a + " " + b);
    }
}

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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    string s,t;
    cin>>s>>t;
    cout << t << s << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

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

  if(a>0&&b>0){ puts("Positive"); return 0;}
  else if((a>0&&b<0)||(a<0&&b>0)){puts("Zero"); return 0;}
  else if(a==0||b==0){puts("Zero"); return 0;}

  if((abs(a-b)+1)%2==0) puts("Positive");
  else puts("Negative");

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,sum=0;
	int d[105];
	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<n;j++){
				if(j!=i){
				sum=sum+(d[i]*d[j]);
				}
			}
		}
		printf("%d",sum/2);
		return 0;
	}
	

Measured memory_bytes: 128
#include <iostream>

using namespace std;
#define MAX 100005
#define NIL -1

struct Node{
    int p, l, r;
};
Node T[MAX];
int n, D[MAX];

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout <<"leaf, ";
    else cout <<"internal node, ";

    cout << "[";
    // 从子结点的最左边开始遍历
    int c = T[u].l;
    while (c != NIL) {
        cout << c;
        if (T[c].r != NIL)
            cout << ", ";
        // 跳到右侧紧邻的兄弟结点
        c = T[c].r;
    }
    cout << "]\n";
}
//递归求深度
int rec(int u, int p){
    D[u] = p;
    if (T[u].r != NIL)  // 右侧兄弟设置为相同深度
        rec(T[u].r, p);
    if (T[u].l != NIL)  // 最左侧子结点的深度设置为自己的深度 + 1
        rec(T[u].l, p + 1);
}
int main()
{
    int d, v, c, l, r;
    cin >> n;
    for (int i = 0; i < n; i++)
        T[i].p = T[i].l = T[i].r = NIL;
    for (int i = 0; i < n; i++){
        cin >> v >> d;
        for (int j = 0; j < d; j++){
            cin >> c;
            if (j == 0)
                T[v].l = c;
            else
                T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (int i = 0; i < n; i++){
        if (T[i].p == NIL)
            r = i;
    }
    rec(r, 0);
    for (int i = 0; i < n; i++)
        print(i);
    return 0;
}



Measured memory_bytes: 7684
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

  		int nums[] = new int[2]; 
      	String str;
      
      	int stack;
      	boolean judge = true;
      	
      	for(int i = 0;i < 2; i++){
        	nums[i] = sc.nextInt();
        }
      

      	str = sc.next();
      	
          for(int i = 0; i < nums[0]; i++){
           	stack = (int)str.charAt(i);
            if(stack < 48 || 57 < stack) judge = false;
          }
          
          if(str.charAt(nums[0]) != '-') judge = false;
     
          for(int i = nums[0] + 1; i < nums[0] + nums[1] + 1; i++){
            stack = (int)str.charAt(i);
            if(stack < 48 || 57 < stack) judge = false;
          }
          if(judge) System.out.println("Yes");
          else System.out.println("No");
	}
}


Measured memory_bytes: 35712
R, G, B, N = map(int, input().split(" "))

ans=0

for count_r in range(N // R + 1):
    currnt_N = N - R * count_r
    for count_g in range(currnt_N // G + 1):
        #pass
        currnt_N = N - R * count_r - G * count_g
        if currnt_N % B == 0:
            ans += 1
            
print(ans)


Measured memory_bytes: 40556
n=int(input())
 
def make_divisors(n):#約数列挙
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def factorization(n):#素因数分解
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt]) 
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1]) 
    return arr

def is_prime(q):#素数判定
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

k=make_divisors(n)#nの約数のリスト
c=0#操作回数
#2つ目の条件よりnの約数を全て探索する・
#最大回数割るためには小さい約数から順に行うのがベスト
for i in range(len(k)):
    if i==0:pass #約数1をpass
    else:
        l1=factorization(k[i])#i-1番目に小さい約数を素因数分解してn乗数かどうかの確認
        seigo=is_prime(l1[0][0])#そのn乗数が素べきかどうかチェック
        #条件1~3を満たす場合のみ操作を行う
        if len(l1)==1 and seigo==True and n%k[i]==0:#最後に割り切れるかどうかのチェック
            n//=k[i]
            c+=1
        
print(c)

Measured memory_bytes: 9552
#include<iostream>
using namespace std;
int main() {
  int N, M, total=0;
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int j;
    cin >> j;
    total += j;
  }
  if(total > N) {
    cout << -1 << endl;
  } else {
    cout << N - total << endl;
  }
  return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> A(n);
  int ans = 0;
  rep(i,n){
    cin >> A[i];
    ans += A[i];
  }
  sort(A.rbegin(),A.rend());
  rep(i,m){
    if(A[i]*m*4 < ans){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef pair<int,int> PII;

const int MAX=2000;
const int INF=1<<28;

int V;//number of vertex
vector<int> G[MAX];
int match[MAX];
bool used[MAX];

void add_edge(int u,int v)
{
	G[u].push_back(v);
	G[v].push_back(u);
	return;
}

bool dfs(int v)
{
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		int u=G[v][i],w=match[u];
		if(w<0||!used[w]&&dfs(w))
		{
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}

int bipartite_matching()
{
	int res=0;
	memset(match,-1,sizeof(match));
	for(int v=0;v<V;v++)
	{
		if(match[v]<0)
		{
			memset(used,0,sizeof(used));
			if(dfs(v))res++;
		}
	}
	return res;
}

int dp[100][100];

int main()
{
	int n,m,l;
	while(cin>>n>>m>>l,n)
	{
		V=2*l;
		rep(i,V)G[i].clear();
		rep(i,n)rep(j,n)dp[i][j]=INF;
		rep(i,n)dp[i][i]=0;
		int u,v,d;
		rep(i,m)
		{
			cin>>u>>v>>d;
			dp[u][v]=d;
			dp[v][u]=d;
		}
		rep(k,n)rep(i,n)rep(j,n)dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
		PII p[1000];
		rep(i,l)cin>>p[i].second>>p[i].first;
		sort(p,p+l);
		rep(i,l)
		{
			int t=p[i].first;
			int to=p[i].second;
			
			for(int j=i+1;j<l;j++)
			{
				if(p[j].first>=t+dp[to][p[j].second])
				{
					add_edge(i,l+j);
				}
			}
		}
		cout<<l-bipartite_matching()<<endl;
	}
	return 0;
}

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

using namespace std; 

const int MAX = 110 ;

long long dp[MAX][MAX][3*MAX] ;
long long w[MAX], v[MAX] ;
int n ;
long long W ;

long long solve(int idx , long long taken , long long sum)
{
	if(taken * w[0] + sum > W)
		return (-1e17) ;
	if(idx == n)
		return 0 ;
	long long &ret = dp[idx][taken][sum] ;
	if(ret != -1)
		return ret ;
	ret = solve(idx+1 , taken , sum) ;
	ret = max(ret,  solve(idx+1 , taken+1 , sum + w[idx] - w[0]) + v[idx]) ;
	return ret ;

}

int main()
{
	memset(dp , -1 , sizeof(dp)) ;
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>W ;
	for(int i = 0 ; i < n ; ++i)
		cin>>w[i]>>v[i] ;
	return cout<<solve(0 , 0ll , 0ll)<<"\n" , 0 ;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  map<int, int> mp;
  rep(i, N) mp[i - A[i]]++;
  ll ans = 0;
  rep(i, N) ans += mp[i + A[i]];
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

  vector<ll> x(n);
  rep(i,n) cin >> x.at(i);

  vector<ll> y(n);
  rep(i,n) y.at(i) = x.at(i);
  sort(y.begin(), y.end());

  ll mid_l=y.at(n/2-1), mid_r=y.at(n/2);
  rep(i,n){
    if(x.at(i)<mid_r) cout << mid_r << endl;
    else cout << mid_l << endl;
  }
}

Measured memory_bytes: 6336
#include <algorithm>
#include <iostream>
#include <iterator>
#include <limits>
#include <sstream>
#include <vector>

using namespace std;
int main() {
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  string s;
  getline(cin, s);
  istringstream is{s};
  istream_iterator<int> ii{is}, eol;
  vector<int> v{ii, eol};
  cin.ignore(numeric_limits<streamsize>::max(), '\n');

  int b, e, t;
  while (cin >> b >> e >> t) {
    swap_ranges(v.begin() + b, v.begin() + e, v.begin() + t);
  }
  cout << v[0];
  for (auto it = ++v.begin(); it != v.end(); ++it)
    cout << " " << *it;
  cout << endl;
}


Measured memory_bytes: 3180
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


struct UF {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UF(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
  int n,m;
  cin >>n>>m;

  vector<int> p(n);
  rep(i,n){
  cin>>p[i];
  }
  
  UF uf(n);
  
  rep(i,m){
  int x,y;
  cin>>x>>y;
  uf.unite(x-1,y-1);
  }
  
  int ans=0;
  rep(i,n){
    if(uf.same(i,p[i]-1)) ans++;
  }
 
  cout << ans << endl;
  
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    for(int i=1; i<10; i++){
        if(n%i==0 && n/i<10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  int n, m; cin >> n >> m;
  Vi a(n), b(n); rep(i,n) { cin >> a[i] >> b[i]; }
  Vi c(m), d(m); rep(i,m) { cin >> c[i] >> d[i]; }
  rep(i,n) {
    int mi = INF;
    int minCheckPoint = 0;
    rep(j,m) {
      int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if ( chmin(mi,dist) ) minCheckPoint = j;
    }
    pl(minCheckPoint+1)
  }
  
  return 0;
}


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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}


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

	string s; cin >> s;
	int n = s.length();
	ll ans = n * (n - 1LL) / 2;
	vi f(26);
	FOR (i, 0, n - 1) {
		ans -= f[s[i] - 'a'];
		f[s[i] - 'a']++;
	}
	cout << ans + 1;

	return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); \
                cin.tie(0); \
                cout.tie(0)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(_v)             _v.begin(), _v.end()
#define sz(_v)              (int) _v.size()
#define first(_obj)         (*_obj.begin())
#define last(_obj)          (*prev(_obj.end()))
#define FIND(_obj, _val)    (_obj.find(_val) != _obj.end())
#define RESET(_a, _v)       fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define REP(_i, _n)         for (int _i = 0; _i < (int) _n; _i++)
#define FOR(_i, _a, _b)     for (int _i = (int) _a; _i <= (int) _b; _i++)
#define FORD(_i, _a, _b)    for (int _i = (int) _a; _i >= (int) _b; _i--)
#define FORIT(_it, _obj)    for (auto _it = _obj.begin(); _it != _obj.end(); _it++)

// DEBUG UTIL
template<typename TF>
void debug(ostream &out, TF const &f) {
    out << f << std::endl;
}
 
template<typename TF, typename ... TR>
void debug(ostream &out, TF const &f, TR const& ... rest) {
    out << f << " ";
    debug( out, rest... );
}
 
#define DEBUG(...) debug(cerr, "[", #__VA_ARGS__, "]:", __VA_ARGS__)

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
using vs = vector<string>;

const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1}; // ccw
const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1};
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1073741823;
const ll INFLL = 4e18;
const int MAX = 3e3;

int N, M, dp[MAX+5][MAX+5];
pii tr[MAX+5][MAX+5];
string s, t;

void read() {
    cin >> s >> t;

    N = sz(s);
    M = sz(t);

    s = " " + s;
    t = " " + t;
}

void solve() {
    FOR(i, 1, N)
        FOR(j, 1, M) {
            if (s[i] == t[j]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                tr[i][j] = {i - 1, j - 1};
            }
            else {
                if (dp[i - 1][j] > dp[i][j - 1]) {
                    dp[i][j] = dp[i - 1][j];
                    tr[i][j] = {i - 1, j};
                }
                else {
                    dp[i][j] = dp[i][j - 1];
                    tr[i][j] = {i, j - 1};
                }
            }
        }

    int ans = dp[N][M];
    pii pos = {N, M};
    vector<char> vec;

    while (ans > 0) {
        pii bef = tr[pos.fi][pos.se];

        if (bef.fi < pos.fi && bef.se < pos.se) {
            vec.pb(s[pos.fi]);
            ans--;
        }

        pos = bef;
    }

    reverse(all(vec));
    for (char c : vec) cout << c;
    cout << "\n";
}

int main() {
    FAST_IO;
    int TC = 1;
    FOR(tc, 1, TC) {
        read();
        solve();
    }
}

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

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

  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    int j[3];
    j[0] = p[i];
    j[1] = p[i+1];
    j[2] = p[i+2];
    int tmp = j[1];
    sort(j, j + 3);
    if (tmp == j[1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,c,k  = map(int, input().split())
ts = [int(input()) for i in range(n)]
ts.sort()
cnt = 0
ans = 0
end = -1
for i, t in enumerate(ts):
    if end < t:
        cnt = 1
        ans += 1
        end = t + k
    else: # t <= end
        cnt += 1
    if cnt > c:
        cnt = 1
        ans += 1
        end = t + k
print(ans)
        

Measured memory_bytes: 71488
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    string s;
    cin >> n >> s;
    unordered_set<int> ans;
    vector<vector<bool>> L(n, vector<bool>(10, false));
    vector<vector<bool>> R(n, vector<bool>(10, false));
    L[0][s[0]-'0'] = true;
    for(int i = 1; i < n; i++) {
        L[i] = L[i-1];
        L[i][s[i]-'0'] = true;
    }
    R[n-1][s[n-1]-'0'] = true;
    for(int i = n-2; i >= 0; i--) {
        R[i] = R[i+1];
        R[i][s[i]-'0'] = true;
    }

    for(int i = 1; i < n-1; i++) {
        for(int l = 0; l < 10; l++) {
            if (L[i-1][l]) {
                for(int r = 0; r < 10; r++) {
                    if (R[i+1][r]) {
                        ans.insert(l*100+(s[i]-'0')*10+r);
                    }
                }
            }
        }
    }
    cout << ans.size() << endl;
    return 0;
}




Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N;
    int x[100],y[100],h[100];
    cin >> N;
    REP(i,N){
        cin >> x[i] >> y[i] >> h[i];
    }
    int H;bool c=true;
    REP(i,101){
        REP(j,101){
            c=true;
            REP(k,N){
                if(h[k]!=0){
                    H=h[k]+abs(i-x[k])+abs(j-y[k]);
                    break;
                }
            }
            REP(k,N){
                if(max((H-abs(i-x[k])-abs(j-y[k])),0ll)!=h[k]){
                    c=false;
                }
            }
            if(c==true){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
    
    
    return 0;
}   


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

int main(){
  string s;
  cin >> s;
  int result;
  
    if(s =="SUN") result = 7;
    else if( s == "MON") result = 6;
    else if( s == "TUE") result = 5;
    else if( s == "WED") result = 4;
    else if( s == "THU") result = 3;
    else if( s == "FRI") result = 2;
    else if( s == "SAT") result = 1;
  
  
  cout << result << endl;
}

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

using namespace std;

int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    
    if(a != 1 && b != 1) printf("1\n");
    if(a != 2 && b != 2) printf("2\n");
    if(a != 3 && b != 3) printf("3\n");

    return 0;
}

Measured memory_bytes: 256
class Array
  def warshall_floyd
    v = size

    used = Array.new(v) { Array.new(v, false) }
    dist = map(&:dup)

    v.times do |k|
      v.times do |i|
        v.times do |j|
          cost = dist[i][k] + dist[k][j]

          if dist[i][j] > cost
            EDGES[i][j] = false
            dist[i][j] = cost
          end
        end
      end
    end

    used
  end
end

N, M = gets.split.map(&:to_i)
graph = Array.new(N) { Array.new(N, Float::INFINITY) }

N.times do |i|
  graph[i][i] = 0
end

edges = M.times.map { gets.split.map(&:to_i) }
EDGES = Hash.new { |h, k| h[k] = Hash.new(false) }

edges.each do |a, b, c|
  EDGES[a - 1][b - 1] = EDGES[b - 1][a - 1] = true
  graph[a - 1][b - 1] = c
  graph[b - 1][a - 1] = c
end

used = graph.warshall_floyd

ans = 0

puts edges.count { |a, b, _| !EDGES[a - 1][b - 1] }



Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

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

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    ll n, k;
    cin >> n >> k;
    cout << min(n % k, abs((n % k) - k)) << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
    int n,i;
    cin>>n;

    vector <int> p(n);

    vector <int> q(n);

    rep(i,n) cin>>p[i];
    rep(i,n) cin>>q[i];

    vector <int> temp=p;

    sort(temp.begin(),temp.end());

    int count1=0,count2=0,ans1=0,ans2=0;

    do{
        count1++;
        count2++;

        if(temp==p){
            ans1=count1;
        }
        if(temp==q){
            ans2=count2;
        }
    }while(next_permutation(temp.begin(),temp.end()));


    cout<<abs(ans1-ans2)<<endl;




return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

ll x[2], y[2];
ll c[3][3];

int main() {
    rep(i,3) rep(j,3) cin >> c[i][j];
    rep(i,2){
        x[i] = c[i+1][0]-c[i][0];
        y[i] = c[0][i+1]-c[0][i];
    }
    rep(i,2){
        rep(j,2){
            if (c[j+1][i+1] - c[j][i+1] != x[j] || c[i+1][j+1] - c[i+1][j] != y[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3644
n = int(input())
lists = list(map(int,input().split()))
ans = 0
count =0
min_num = 999999
for i in lists:
    if i<0:
        count+=1
if(count%2==0):
    for i in lists:
        ans += abs(i)
else:
    for i in lists:
        if abs(i) < min_num:
                min_num = abs(i)
    for i in lists:
        ans += abs(i)
    ans -= min_num*2
print(ans)

Measured memory_bytes: 14208
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String n = in.next();
        int sum = 0;
        for (int i = 0; i < n.length(); i++){
            sum += Character.getNumericValue(n.charAt(i));
        }
        if (Integer.parseInt(n) % sum!= 0){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }

    }
}


Measured memory_bytes: 23252
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [n] <- readInt
  a   <- replicateM n $ do
    [m] <- readInt
    x   <- map toPair <$> readInts m
    return (m, x)
  print $ solve n a

solve :: Int -> [(Int, [(Int, Int)])] -> Int
solve n a = maximum $ map fromJust $ filter (/= Nothing) $ map (\b -> f b a)
                                                               bit
  where bit = replicateM n [True, False]

f :: [Bool] -> [(Int, [(Int, Int)])] -> Maybe Int
f bit a | s bits 0 a' = Just $ length $ filter (== True) bit
        | otherwise   = Nothing
 where
  bits = V.fromList bit
  a'   = map snd a

s :: V.Vector Bool -> Int -> [[(Int, Int)]] -> Bool
s bits i (a : as) | bits V.! i = g bits a && s bits (i + 1) as
                  | otherwise  = s bits (i + 1) as
s _ _ _ = True

g :: V.Vector Bool -> [(Int, Int)] -> Bool
g bits = all (h bits)

h :: V.Vector Bool -> (Int, Int) -> Bool
h bits (x, y) | y == 1 && bits V.! (x - 1)       = True
              | y == 0 && not (bits V.! (x - 1)) = True
              | otherwise                        = False


Measured memory_bytes: 4220
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int n, i, j, k;
	string rgbs;
	ll answer = 0;
	ll r, g, b;
	r = g = b = 0;
	cin >> n;
	cin >> rgbs;
	for (i = 0; i < n; i++) {
		if (rgbs[i] == 'R')
			r++;
		else if (rgbs[i] == 'G')
			g++;
		else
			b++;
	}
	answer += r * g * b;

	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j < n; j++) {
			k = j + (j - i);
			if (k >= n)
			    break;
			if (rgbs[i] == rgbs[j])
				continue;
			if (rgbs[j] == rgbs[k])
				continue;
			if (rgbs[i] == rgbs[k])
				continue;
			answer--;
		}
	}

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3632
import math

a, b, x = map(int, input().split())

V = a * a * b

if V == x:
    print (0)
    exit()

if x * 2 <= V:
    tmp = 2 * x / (a * b * b)
else:
    tmp = a / (2 * (b - x / (a ** 2)))

print (90 - math.degrees(math.atan(tmp)))


Measured memory_bytes: 3316