akhauriyash/Code-Regression huggingface dataset:
module mod_weighted_union_find
  implicit none
  type weighted_union_find
    integer :: n = 0
    integer, allocatable :: par(:), rnk(:), cnt(:), pot(:)
  contains
    procedure :: find => find
    procedure :: weight => weight
    procedure :: same => same
    procedure :: unite => unite
    procedure :: diff => diff
    procedure :: size => size_of
  end type
  interface weighted_union_find
    module procedure :: newwuf
  end interface weighted_union_find
contains
  type(weighted_union_find) function newwuf(n) result(res)
    integer, intent(in) :: n
    integer :: i
    res%n = n
    allocate(res%par(n), res%rnk(n), res%cnt(n), res%pot(n))
    res%par = [(i, i = 1, n)]
    res%rnk = 0
    res%cnt = 1
    res%pot = 0
  end
  recursive integer function find(this, i) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i
    integer :: p
    if (this%par(i) == i) then
      res = i
      return
    end if
    p = find(this, this%par(i))
    this%pot(i) = this%pot(i) + this%pot(this%par(i))
    this%par(i) = p
    res = p
  end
  integer function weight(this, i) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i
    integer :: p
    p = find(this, i)
    res = this%pot(i)
  end
  logical function same(this, i, j) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    res = find(this, i) == find(this, j)
  end
  subroutine unite(this, i, j, w)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i, j, w
    integer :: x, y, z
    z = w + weight(this, i) - weight(this, j)
    x = find(this, i)
    y = find(this, j)
    if (x == y) return
    if (this%rnk(x) < this%rnk(y)) then
      call swap(x, y)
      z = -z
    end if
    if (this%rnk(x) == this%rnk(y)) this%rnk(x) = this%rnk(x) + 1
    this%par(y) = x
    this%pot(y) = z
  end
  integer function diff(this, i, j) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    res = weight(this, j) - weight(this, i)
  end
  integer function size_of(this, i) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i
    res = this%cnt(find(this, i))
  end
  subroutine swap(a, b)
    integer, intent(inout) :: a, b
    a = xor(a, b)
    b = xor(a, b)
    a = xor(a, b)
  end
end module mod_weighted_union_find
program people_on_a_line
  use mod_weighted_union_find
  implicit none
  integer :: n, m, l, r, d, i
  type(weighted_union_find) :: wuf
  read(*,*) n, m
  wuf = weighted_union_find(n)
  do i = 1, m
    read(*,*) l, r, d
    if (wuf%same(l, r)) then
      if (wuf%diff(l, r) /= d) then
        write(*,'(a)') 'No'
        stop
      end if
    else
      call wuf%unite(l, r, d)
    end if
  end do
  write(*,'(a)') 'Yes'
end program people_on_a_line

Measured memory_bytes: 4492
using System;
using System.Collections.Generic;
class Solve{
    string s;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        for(int i=0;i<s.Length-1;i++){
            if(i != s.Length-2 && s[i] == s[i+2]){
                Console.Write(i+1);
                Console.Write(" ");
                Console.WriteLine(i+3);
                return;
            }
            if(s[i] == s[i+1]){
                Console.Write(i+1);
                Console.Write(" ");
                Console.WriteLine(i+2);
                return;
            }
        }
        Console.WriteLine("-1 -1");
    }
    void getinput(){
        s = Console.ReadLine();
    }    
}

Measured memory_bytes: 3032
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;
const double PI = acos(-1);

int main(){
    int N; 
    cin >> N;
    vector<ll> a(N);
    int c = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        c ^= a[i];
    }
    for(int i = 0; i < N; i++){
        int ans = c ^ a[i];
        cout << ans << ' ';
    }
    cout<<endl;
}

Measured memory_bytes: 4772
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

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

  for(int i = 0; i < N; i++) {
    int K, P; cin >> K >> P;
    cout << (K % P ? K % P : P) << endl;
  }
}

Measured memory_bytes: 1164
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int H,W;
bool field[2005][2005];

int dpr[2005][2005];
int dpc[2005][2005];

int solve(void) {
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            if(!field[i][j]) {
                if(j > 0)
                    dpc[i][j] = dpc[i][j-1]+1;
                else
                    dpc[i][j] = 1;
            } else {
                dpc[i][j] = 0;
            }
        }

        for(int j = W-2;j >= 0;j--) {
            if(dpc[i][j+1] == 0) {
            } else if(dpc[i][j] != 0) {
                dpc[i][j] = dpc[i][j+1];
            }
        }
    }


    for(int j = 0;j < W;j++) {
        for(int i = 0;i < H;i++) {
            if(!field[i][j]) {
                if(i > 0) {
                    dpr[i][j] = dpr[i-1][j]+1;
                } else {
                    dpr[i][j] = 1;
                }
            } else {
                dpr[i][j] = 0;
            }
        }

        for(int i = H-2;i >= 0;i--) {
            if(dpr[i+1][j] == 0) {

            } else if(dpr[i][j] != 0) {
                dpr[i][j] = dpr[i+1][j];
            }
        }
    }

    int light= 0;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            light = max(light,dpr[i][j]+dpc[i][j]-1);
        }
    }

    return light > 0 ? light : 0;
}

int main(void) {
    cin>>H>>W;

    for(int i = 0;i < H;i++) {
        string str;
        cin>>str;
        for(int j = 0;j < W;j++) {
            if(str[j] == '.') {
                field[i][j] = 0;
            } else {
                field[i][j] = 1;
            }
        }
    }

    cout<<solve()<<endl;

    return 0;
}


Measured memory_bytes: 35584
#B
n = int(input())
s = str(n)
l = len(s)

cnt = 0

for i in range(1,l+1):
    s = str(n)
    l = len(s)
    if i % 2 == 1:
        if n < 10:
            cnt += n
            break
        elif i == 1:
            cnt += 9
            
        elif n < 10**i:
            cnt += n - 10**(i-1) + 1
            
            
        else:
            cnt += 10**(i) - 10**(i-1)
print(cnt)
            

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

int N, M, Q;
int quad[51][4];
ll brute(int i, int j, vi build) {
  if (j > M) return 0;
  if (i == N) {
    ll ret = 0;
    rep(i, 0, Q) {
      int a = quad[i][0] - 1;
      int b = quad[i][1] - 1;
      int c = quad[i][2];
      if (build[b] - build[a] == c)
        ret += quad[i][3];
    }
    return ret;
  }

  vi nu(build); nu.pb(j);
  ll mx = max(brute(i + 1, j, nu), brute(i, j + 1, build));
  return mx;
}

// aaaaaaaaaaaaaaaa
void solve() {
  scanf("%d%d%d", &N, &M, &Q);
  rep(i, 0, Q) rep(j, 0, 4)
    scanf("%d", &quad[i][j]);
  printf("%lld\n", brute(0, 1, vi(0)));  
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}



Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <map>
#include <unordered_map>
#include <tuple>
 
using namespace std;
 
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define umap unordered_map
#define uset unordered_set
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(s, n, a) for(int i = s; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES\n" : "NO\n")
#define mod(a, b) (b + (a % b)) % b
#define MOD (int)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

void add_self (int& a, int b){ a += b; if (a >= MOD) a -= MOD; }
//-------------------------------------------------------------------------------------------------------//

void solve(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        ans += x - 1;
    }
    cout << ans;
    
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int r[100001],f[100001];
queue<int> q;
vector<int> g[100001];
int main()
{
	int i,n,m,x,y,ans=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		r[y]++;
	}
	for(i=1;i<=n;i++)
		if(r[i]==0)
			q.push(i);
	while(!q.empty())
	{
		int a=q.front();
		q.pop();
		for(i=0;i<g[a].size();i++)
		{	
			f[g[a][i]]=max(f[g[a][i]],f[a]+1);
			r[g[a][i]]--;
			if(r[g[a][i]]==0)
				q.push(g[a][i]);
		}
	}
	for(i=1;i<=n;i++)
		ans=max(ans,f[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <cmath>

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

    int64_t N, A, B, C, D, E;
    std::cin >> N >> A >> B >> C >> D >> E;

    int64_t bottleNeck = std::min(A,B);
    bottleNeck = std::min(bottleNeck, C);
    bottleNeck = std::min(bottleNeck, D);
    bottleNeck = std::min(bottleNeck, E);

    int64_t bottleNeck_time = std::ceil((double) N / bottleNeck);
    std::cout << bottleNeck_time + 4 << std::endl;


    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
ans = 0
minimum = min(a, b, c, d, e)

if a == minimum:
    ans = -(-n//a) + 4
elif b == minimum:
    ans = -(-n//b) + 4
elif c == minimum:
    ans = -(-n//c) + 4
elif d == minimum:
    ans = -(-n//d) + 4
elif e == minimum:
    ans = -(-n//e) + 4
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

string s, t;
Int q;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s >> t >> q;
	vector<Int> a(s.size()+1);
	vector<Int> b(t.size()+1);
	for(size_t i=0; i<s.size(); ++i)
		a[i+1] = s[i] == 'B' ? 2 : 1;
	for(size_t i=0; i<t.size(); ++i)
		b[i+1] = t[i] == 'B' ? 2 : 1;
	for(size_t i=1; i<a.size(); ++i)
		a[i] += a[i-1];
	for(size_t i=1; i<b.size(); ++i)
		b[i] += b[i-1];
	while(q--){
		Int x, y, z, w;
		cin >> x >> y >> z >> w;
		Int t = a[y] - a[x-1];
		Int s = b[w] - b[z-1];
		cout << ((t - s) % 3 == 0 ? "YES" : "NO") << "\n";
	}
}

Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;

int main () {

    int N, M, R;
    scanf("%d %d %d", &N, &M, &R);

    int r[R];
    for (int i = 0; i < R; i++) {
        scanf("%d", &r[i]);
        r[i]--;
    }

    int map[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            map[i][j] = ((i == j)? 0 : INF);
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        map[a][b] = map[b][a] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (map[i][k] < INF && map[k][j] < INF) {
                    map[i][j] = min(map[i][k] + map[k][j], map[i][j]);
                }
            }
        }
    }

    sort(r, r + R);

    int ans = INF;
    do {
        int cost = 0;
        for (int i = 1; i < R; i++) {
            cost += map[r[i-1]][r[i]];
        }
        ans = min(ans, cost);
    } while (next_permutation(r, r + R));

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

    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    if (A == 1) A += 13;
    if (B == 1) B += 13;

    if (A < B) {
        cout << "Bob" << endl;
    } else if (A > B) {
        cout << "Alice" << endl;
    } else {
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
    #include<string.h>
    int main()
    {
      char s[10000];
      scanf(" %[^\n]",s);
      printf("%c",s[0]);
      for(int i=0;i<strlen(s);i++){
        if(s[i]==' '){
            printf("%c",s[i+1]);
        }
      }
 
        return 0;
    }

Measured memory_bytes: 1644
package main

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

func main() {
	K := ReadInt()
	A := ReadInts(K)

	if A[K-1] != 2 {
		fmt.Println(-1)
		return
	}

	l, r := 2, 3
	for i := K - 2; i >= 0; i-- {
		l = (l + A[i] - 1) / A[i] * A[i]
		r = r/A[i]*A[i] + A[i] - 1
		if l > r {
			fmt.Println(-1)
			return
		}
	}
	fmt.Printf("%d %d\n", l, r)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4296
s = input()
count0 = 0
count1 = 0
for i in range(len(s)):
    if i%2:
        if s[i] == "0": count0+=1
        else: count1+=1
    else:
        if s[i] == "0": count1+=1
        else: count0+=1
print(min(count0, count1))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll sentou(ll x){
	while(x/10 > 0){
		x /= 10;
	}
	return x;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll cnt[10][10];
	memset(cnt, 0, sizeof(cnt));
	
	ll n;
	cin >> n;
	rep(i, 1, n){
		cnt[sentou(i)][i%10]++;
	}
	ll ans = 0;
	zep(i, 0, 10){
		zep(j, 0, 10){
			//cout << cnt[i][j] << " ";
			ans += cnt[i][j]*cnt[j][i];
		}
		//cout << endl;
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<ll> a(n);
  REP(i, n) {
    if (s[i] == 'R') {
      a[i] = 0;
    } else if (s[i] == 'G') {
      a[i] = 1;
    } else {
      a[i] = 2;
    }
  }
  ll ans = 0;
  vector<vector<ll>> l(3, vector<ll>(n + 1, 0));
  vector<vector<ll>> r(3, vector<ll>(n + 1, 0));
  REP(i, 3) REP(j, n) { l[i][j + 1] = l[i][j] + (a[j] == i); }
  reverse(ALL(a));
  REP(i, 3) REP(j, n) { r[i][j + 1] = r[i][j] + (a[j] == i); }
  reverse(ALL(a));

  // REP(i, 3) {
  //   REP(j, n + 1) { cout << r[i][j] << " \n"[j == n]; }
  // }

  // REP(i, n) { cout << a[i] << " \n"[i == n - 1]; }

  FOR(j, 1, n - 1) {
    // DUMP(ans);
    FOR(k, 1, n + 1) {
      ll L = j - k, R = j + k;
      if (L < 0 || R >= n) {
        break;
      }
      if (s[L] != s[j] && s[L] != s[R] && s[j] != s[R]) {
        ans--;
      }
    }
    vector<ll> c;
    REP(i, 3) {
      if (i != a[j]) {
        c.push_back(i);
      }
    }
    // DUMP(SZ(c));
    ll x = c[0], y = c[1];
    // DUMP(x);
    // DUMP(y);
    // DUMP(ans);
    ans += l[x][j] * r[y][n - j] + l[y][j] * r[x][n - j];
    // DUMP(ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3740
def divisors(N):
    res = []
    i = 1
    while i * i < N:
        if N % i == 0:
            res.extend([i, N // i])
        i += 1
    if i * i == N and N % i == 0:
        res.append(i)
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int len=str.length();
        String[] STR = str.split("");
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String q = sc.next();
            int a = sc.nextInt();
            int b = sc.nextInt();
            
            if (q.equals("print")) {
                System.out.println(str.substring(a, b+1));
                
            } else if (q.equals("reverse")) {
                StringBuffer sb = new StringBuffer(str.substring(a, b+1));
                String rev = sb.reverse().toString();
                str = str.substring(0, a) + rev + str.substring(b+1, str.length());
                
            } else if (q.equals("replace")) {
                String p = sc.next();
                String s1=str.substring(0,a);
                String s2=str.substring(b+1,str.length());
                str=s1+p+s2;
            }
        }
        sc.close(); 
    }
}


Measured memory_bytes: 30096
#include<iostream>
#include<cstdio>
#define max(a,b) (a)>(b)?(a):(b)
using namespace std;
int a[3005][2];
int dp[3005][3005];
int main(){
	int n,t,t2;
	int i,j,k;
	cin>>n>>t>>t2;
	for(i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=t;j++){
			if(j<a[i-1][1] || (j-a[i-1][1]<t2 && t2<j)){
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
				continue;
			}
			dp[i][j]=max(max(dp[i][j-1],dp[i-1][j]),dp[i-1][j-a[i-1][1]]+a[i-1][0]);
		}
	}
	cout<<dp[n][t]<<endl;
	return 0;
}

Measured memory_bytes: 38308
#include<stdio.h>
int main()
{
    int a,b,c,d,e;

    scanf("%d %d",&a,&b);

    c=a+b;
    d=a-b;
    e=a*b;

    if(c>=d && c>=e){
    printf("%d\n",c);
    }
    else if(d>=c && d>=e){
    printf("%d\n",d);
    }
    else if(e>=c && e>=d)
 {
     printf("%d\n",e);
 }









return 0;








}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main(){
		new UF().doIt();		
	}
	
	class UF{
		class UnionFind{
			int par[]; //???
			int rank[];
			UnionFind(int n){
				rank = new int[n];
				par=new int[n];
				for(int i=0;i<n;i++)par[i]=i;
			}
			int find(int x){
				if(par[x] == x) return x;
				else return par[x] = find(par[x]);
			}
			//x??¨y????±??????????????????????
			void unite(int x,int y){
				x = find(x);
				y = find(y);
				if(x == y)return;
				if(rank[x] < rank[y]){
					par[x] = y;
				}else {
					par[y] = x;
					if(rank[x] == rank[y])rank[x]++;
				}
			}
			//x??¨y???????????????????±????????????????
			boolean same(int x,int y){
				return find(x) == find(y);
			}
		}
		void doIt() { 
			int n = sc.nextInt();
			int q = sc.nextInt();
			UnionFind uf = new UnionFind(n);
			for(int i = 0;i < q;i++){
				int com = sc.nextInt();
				int x = sc.nextInt();
				int y = sc.nextInt();
				if(com==0) uf.unite(x, y);
	            else{
	            	if(uf.same(x, y))System.out.println("1");
	            	else System.out.println("0");
	            }
			}
		}
	}
}

Measured memory_bytes: 95088
m,p,a,b,c,i,j,t;main(n){for(;t=999+scanf("%d%d",&n,&m),n;printf("%d\n",c<2?a+1:n))for(i=c=0;i<n;i++)scanf("%d",&b),j=m/b*b,(j<t||j==t&&b<=p)&&(c=j==t&&b==p?c+1:1,t=j,p=b,a=i);exit(0);}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)

const ll N = 123456;
const ll mod = 998244353;
const ld eps = 1e-5;

ll a[N];
ll dp[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cout.precision(10);

    int n;
    cin >> n;

    rep(i , 1 , n) cin >> a[i];

    dp[1] = 0;

    dp[2] = abs(a[2] - a[1]);
    rep(i , 3 , n) {
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]) , dp[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1792
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .chars()
        .map(|x| x.to_string().parse::<i32>().unwrap())
        .collect::<Vec<_>>();

    let a = (list[0] - 1) + 9 * ((list.len() as i32) - 1);
    let b = list.into_iter().sum::<i32>();
    if a > b { a } else { b }.to_string()
}

#[test]
fn test() {
    let tests = vec![("100", "18"), ("9995", "35"), ("3141592653589793", "137")];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vaibhav Pulastya
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BStringsWithTheSameLength solver = new BStringsWithTheSameLength();
        solver.solve(1, in, out);
        out.close();
    }

    static class BStringsWithTheSameLength {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            String t = in.next();
            StringBuilder ss = new StringBuilder();
            for (int i = 0; i < n; i++) {
                ss.append(s.charAt(i));
                ss.append(t.charAt(i));
            }
            out.println(ss.toString());
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 32384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] F = new int[N][10];
		int[][] P = new int[N][11];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 10; j++) {
				F[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 11; j++) {
				P[i][j] = sc.nextInt();
			}
		}
		long ans = -1000000000;
		for (int i = 1; i < (1 << 10); i++) {
			long bene = 0;
			for (int j = 0; j < N; j++) {
				int cnt = 0;
				for (int k = 0; k < 10; k++) {
					if ((i >> k & 1) == 1 && F[j][k] == 1)
						cnt++;
				}
				bene += P[j][cnt];
			}
			ans = Math.max(ans, bene);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 26572
#include<iostream>
#include<string>

int main(void){
  //500円玉A枚，100円玉B枚，50円玉C枚でX円を作る。
  int A, B, C, X;
  int cnt = 0, total;
  std::cin >> A >> B >> C >> X;
  for(int a = 0; a <= A; a++){
    for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
        total = 500*a + 100*b + 50*c;
        if(total == X){++cnt;}
      }
    }
  }
  std::cout << cnt << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            graph.add(new ArrayList<>());
        }
        int[] types = new int[n];
        for (int i = 0; i < n; i++) {
            int x = sc.next().charAt(0) - 'a';
            graph.get(x).add(i);
            types[i] = x;
        }
        int[] costs = new int[n];
        Arrays.fill(costs, Integer.MAX_VALUE);
        PriorityQueue<Path> queue = new PriorityQueue<>();
        queue.add(new Path(0, 0));
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (p.idx >= n) {
                continue;
            }
            if (costs[p.idx] <= p.value) {
                continue;
            }
            costs[p.idx] = p.value;
            queue.add(new Path(p.idx + 1, p.value + 1));
            for (int x : graph.get(types[p.idx])) {
                if (x <= p.idx) {
                    continue;
                }
                queue.add(new Path(x, p.value));
            }
            graph.get(types[p.idx]).clear();
        }
        System.out.println(costs[n - 1] + 1);
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int value;
        
        public Path(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}


Measured memory_bytes: 74552
while True:
    w,h=map(int, input().split())
    if w==h==0:
        break
    xs,ys=map(int, input().split())
    xg,yg=map(int, input().split())
    xs-=1
    ys-=1
    xg-=1
    yg-=1
    n=int(input())
    dataset=[]
    for _ in range(n):
        dataset.append(list(map(int,input().split())))

    maze=[ [0 for i in range(w) ] for j in range(h)]

    for data in dataset:
        color=data[0]
        drc=data[1]
        x=data[2]-1
        y=data[3]-1
        x_list=[x,x+1] if drc==1 else [x,x+1,x+2,x+3]   
        y_list=[y,y+1,y+2,y+3] if drc==1 else [y,y+1]

        for dy in y_list:
            for dx in x_list:
                maze[dy][dx]=color

    history=[[-1 for i in range(w)] for j in range(h)]
    ws=[]
    dx_list=[0,0,1,-1]
    dy_list=[1,-1,0,0]

    flag=False

    if maze[ys][xs]!=0:
        ws.append([xs,ys])

    while len(ws)!=0:
        current=ws.pop(0)
        current_color=maze[current[1]][current[0]]
        if current[0]==xg and current[1]==yg:
            flag=True 
            break
        for dx,dy in zip(dx_list,dy_list):
            next_x=current[0]+dx
            next_y=current[1]+dy
            if next_x>=0 and next_x<w and next_y>=0 and next_y<h and maze[next_y][next_x]==current_color and history[next_y][next_x]==-1:
                history[next_y][next_x]=0
                ws.append([next_x,next_y])

    if flag:
        print('OK')
    else:
        print('NG')



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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

ll inv(ll x,int p){
	if (p==0)
		return 1;
	if (p==1)
		return x;
	ll ret=inv(x,p>>1);
	ret = ret*ret % mod;
	return ret * inv(x,p&1) % mod; 
}

ll nck(int k) {  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
  
    for (int i = 0; i < k; ++i)  {  
        res = res*(n - i)%mod;  
        res = res*inv(i + 1,mod-2)%mod;  
    }  
  
    return res;  
} 

int main(){
	//IO();
	int a,b;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	ll ans=(inv(2,n)-1-nck(a)+mod)%mod;
	ans = (ans-nck(b)+mod)%mod;
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
/**
 *   author: sahushivam
 *   created: 16 November 2019 (Saturday)  17:32:01
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for(int i = a; i<b; i++)
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t=1;
    cin>>t;
    string s;
    cin>>s;
    if(t&1) cout<<"No\n";
    else
    {
    	bool flag=1;
    	int i=0;
    	int j=t/2;
    	while(i<t/2)
    	{
    		if(s[i++]!=s[j++])
    		{
    			flag=0;
    			break;
    		}
    	}
    	if(flag) cout<<"Yes\n";
    	else cout<<"No\n";
    }
return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int max_n = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = i+1; j < N; j++){
            max_n = max(max_n, abs(A[i] - A[j]));
        }
    }
    cout << max_n << endl;
}


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

int main(){
    int a, b;
    string s;
    bool flag = true;
    cin >> a >> b >> s;

    for (int i = 0; i < s.size(); i++)
    {
        if(i == a)
        {
            if (s.at(i) != '-')
            {
                flag = false;
                break;
            }
        }
        else
        {
            if (s.at(i) < '0' || s.at(i) > '9')
            {
                flag = false;
                break;
            }
        }
    }

    if (flag) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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);
}

int main() {
    
    ll n, m;
    cin >> n >> m;
    vector<pair<int,int>> z(m);
    vector<int> ki;
    ki = {100,2,5,5,4,5,6,3,7,6};
    for (int i = 0; i < m; i++) {
        cin >> z[i].second;
        z[i].first = ki[z[i].second];
    }
    
    vector<vector<ll>> ans(n + 1,vector<ll>(10,-100000));
    
    ans[0] = {0,0,0,0,0,0,0,0,0,0};
    
    for (int i = 1; i < n + 1; i++) {
        for (int j = 0; j < z.size(); j++) {
            if (i >= z[j].first) {
                vector<ll> y(10);
                for (int k = 0; k < 10; k++) {
                    y[k] = ans[i - z[j].first][k];
                }
                y[0]++;
                y[10 - z[j].second]++; 
                
                ans[i] = max(ans[i], y);
            }
        }
    }
    for (int i = 1; i < 10; i++) {
        for (int j = 0; j < ans[n][i]; j++) {
            cout << 10 - i;
        }
    }
    cout << endl;
}

Measured memory_bytes: 4496
#include<stdio.h>
int color[105],k[105],d[105],G[105][105],Qu[100];
int u,v,j=0,count=1,n;
void Enqueue(int s){
  int i=0;
  while(i<k[s]){ 
    Qu[count]=G[s][i];
    ++i;
    ++count;
  }
}
int Dequeue(){
  int head,i;
  head=Qu[0];
  for(i=0;i<count;i++)
    Qu[i]=Qu[i+1];
  --count;
  return head;
}
void BFS(int s){
  int i;
  Qu[0]=s;
  for(i=1;i<=n;i++){
    color[i]=0;
    d[i]=-1;
  }
  color[s]=2;
  d[s]=0;
  Qu[0]=s;
  Enqueue(s);
  while(Qu[0]!=NULL){
    u=Dequeue();
    for(i=0;i<k[u];i++)
      if(color[G[u][i]]==0){
	color[G[u][i]]=2;
	d[G[u][i]]=d[u]+1;
	Enqueue(G[u][i]);
      }
    color[u]=1;
  }
}
int main(void){
  int i,j,k1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k1);
    k[u]=k1;
    for(j=0;j<k[u];j++){
      scanf("%d",&v);
      G[u][j]=v;
    }  
  } 
  BFS(1);
  for(i=1;i<=n;i++)
    printf("%d %d\n",i,d[i]);
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define D  double
typedef pair<D,int>T;
int N;
int X[1111],Y[1111],R[1111];
D dist[1111];
D INF=1e15;
D EPS=1e-12;
int table2[1111][1111];
D table[1111][1111];

bool used[1111];
signed main(){

    cin>>X[0]>>Y[0]>>X[1]>>Y[1];
    cin>>N;
    rep(i,N)cin>>X[i+2]>>Y[i+2]>>R[i+2];
    N+=2;

    rep(i,N)rep(j,N){
        table2[i][j]=(X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
        table[i][j]=sqrt(1.0*table2[i][j]);
    }

    fill_n(dist,N,INF);
    dist[0]=0;

    while(true){
        int v=-1;
        rep(i,N)if(!used[i]&&(v==-1||dist[i]<dist[v]))v=i;
        if(v==-1)break;
        used[v]=true;
        rep(i,N){
            D cost=0.0;
            int foo=table2[i][v];
            int bar=R[i]+R[v];
            if(foo>bar*bar)cost=table[i][v]-bar;
            chmin(dist[i],dist[v]+cost);
        }
    }
    printf("%.20f\n",dist[1]);
    return 0;
}


Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,p; cin >> a >> p;
    p += a * 3;
    cout << p / 2 << endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

    string c;
    cin >> c;

    vector<string> v = {"a", "e", "i", "o", "u"};
    cout << (find(v.begin(), v.end(), c) == v.end() ? "consonant" : "vowel") << endl;
    
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int 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
n=gets.to_i
a=gets.split.map &:to_i
if n<3
    p 1
else
    res=1
    d=a[1]-a[0]
    for i in 2...n
        t=a[i]-a[i-1]
        if d*t<0
            res+=1
            d=0
        elsif t!=0
            d=t
        end
    end
    p res
end


Measured memory_bytes: 8452
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m]
    }
    let mut g = vec![vec![]; n];
    for (a, b) in ab {
        g[a].push(b);
        g[b].push(a);
    }

    let mut q = VecDeque::new();
    q.push_back(0);
    let mut ans = vec![n; n];

    while let Some(p) = q.pop_front() {
        for &next in g[p].iter() {
            if ans[next] != n {
                continue;
            }
            ans[next] = p;
            q.push_back(next);
        }
    }

    if ans.iter().any(|&s| s == n) {
        println!("{}", "No");
    } else {
        println!("{}", "Yes");
        for a in ans[1..].iter() {
            println!("{}", a + 1);
        }
    }
}


Measured memory_bytes: 16056
#include <stdio.h>
#include <iostream>
using namespace std;
#include <algorithm>
int a[5];
int main()
 {
     for (int i=1; i<=3; i++)
     {
         scanf ("%d",&a[i]);
     }
     sort(a+1,a+4);
     printf ("%d\n",a[1]+a[2]);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0; i<s.size()-2; i++)
  {
    if(s[i] == 'A' && s[i+1] =='B' && s[i+2] == 'C'){
    	ans++;
    }
  }
  
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 384
n, m = map(int, input().split())
l = []
combo = []
for i in range(max(n, m)+1):
  l.append([])
  
def dfs(path, now):
  if len(set(path)) == n and not path in combo:
    combo.append(path)
    return

  for i in l[now]:
    if not i in path:
      temp = path[:]
      temp.append(i)
      dfs(temp, i)

  return

if m == 0:
  print(0)
else:

  for i in range(m):
    f, t = map(int, input().split())
    if not t in l[f]:
      l[f].append(t)
    
    if not f in l[t]:
      l[t].append(f)

  dfs([1], 1)
  print(len(combo))

Measured memory_bytes: 3832
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
4 2
5 2
2 1
8 3

output:
13
"""

import sys
from collections import namedtuple


# def solve():
#     for i, item in enumerate(item_list, 1):
#         for cp in range(1, real_cp + 1):
#             # capacity allows putting in, calculate value
#             if item.w <= cp:
#                 values[i][cp] = max(values[i - 1][cp], values[i - 1][cp - item.w] + item.v)
#             # can't put in, skip current item
#             else:
#                 values[i][cp] = values[i - 1][cp]
#
#     return values[c_items][real_cp]


def solve_2():
    dp = [0] * (real_cp + 1)
    for item in item_list:
        v, w = item.v, item.w
        for cp in range(real_cp - w, -1, -1):
            dp[cp + w] = max(dp[cp + w], dp[cp] + v)

    return dp[-1]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_items, real_cp = map(int, _input[0].split())
    items = map(lambda x: x.split(), _input[1:])

    Item = namedtuple('Item', ('v', 'w'))
    item_list = [Item(int(v), int(w)) for v, w in items]

    # values = [[0] * (real_cp + 1) for _ in range(c_items + 1)]
    print(solve_2())

Measured memory_bytes: 8336
$n=<>;
($t,$a)=glob<>;
@h=glob<>;
$x=($t-$a)/0.006;
$d=2<<30;
for($i=1;$i<=$n;$i++){
    if($d>abs(@h[$i-1]-$x)){
        $k=$i;
        $d=abs(@h[$i-1]-$x);
    }
}
print $k


Measured memory_bytes: 1024
n, m = gets.chomp.split.map(&:to_i)

py = Array.new(m)
m.times do |i|
  py[i] = gets.chomp.split.map(&:to_i)
end

sort_no_max = Array.new(n, 1)
py.sort { |a, b| a[1] <=> b[1] }.each do |ppyy|
  p = ppyy[0] - 1
  ppyy << sort_no_max[p]
  sort_no_max[p] += 1
end

py.each do |pp, yy, ii|
  puts pp.to_s.rjust(6, "0") + ii.to_s.rjust(6, "0")
end


Measured memory_bytes: 13164
#include <iostream>
#include <cstdio>

using namespace std;

typedef unsigned long long ull;

int main()
{
    ull S, c;
    
    cin >> S >> c;
    
    if ( (S <= 1 && c <= 1) || (S <= 0 && c <= 3) )
    {
        return 0;
    }
    
    ull ans = 0;
    ull cPair = c / 2;
    
    // cPair を満たす S なら cPair が答え
    if (S >= cPair)
    {
        ans = cPair;
    }
    // そうでないならば、残った c から S を作る
    else
    {
        ans = S;
        c -= S * 2;
        ans += c / 4;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>  DVector;
int n;

//kが10^18だから2の五千兆乗以下
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int k;  //最初から何番目か
    //5000兆 = 5000000000000000
    //unsigned long long day = 5000000000000000;
    
    cin >> s >> k;
    int len = s.size();
    int char_counter_origin[len];
    //unsigned long long char_counter[len];
    
    rep(i, len){
        char_counter_origin[i] = s[i] - '0';
        //char_counter[i] = pow(char_counter_origin[i], day);
    }
    /*
    cout << "char_counterの数" << endl;
    rep(i, len){
        cout << char_counter[i] << endl;
    }*/
    
    int ans;
    for(int i = 0;; ++i){
        ans = char_counter_origin[i];
        
        if(ans == 1){
            k -= 1;
        }else{
            //cout << "答え" << endl;
            cout << ans << endl;
            return 0;
            //break;
        }
        
        if(k == 0){
            //cout << "答え" << endl;
            cout << ans << endl;
            return 0;
            //break;
        }
    }
    
    /*
    cout << "元の文字列表示" << endl;
    rep(i, len){
        cout << char_counter_origin[i] << endl;
    }*/
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;



/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

//#define int long long

void solve(){

	int n;
	cin>>n;

	while(n){

		int x = n%10;

		if(x==7){

			cout<<"Yes\n";
			return;
		}
		n/=10;
	}

	cout<<"No\n";
}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t ; ++i){

    	solve();
    	
    	//cout<<"Case #"<<i<<": ";
    }
}


Measured memory_bytes: 3632