akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main()
{
	long long n, m, total = 0;
	scanf("%lld%lld", &n, &m);
	total += min(n, m / 2);
	m -= total * 2;
	total += m / 4;
	printf("%lld\n", total);
}

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

bool isPrimeNumber(int num) {
  int rootInt = sqrt(num);
  if (num == 1 || num <= 0) return false;
  for (int i=2; i<=rootInt; i++) {
    if (num % i == 0) return false;
  }
  return true;
  
}

int main() {
  int N; cin >> N;
  int num;
  int counter = 0;
  for (int i=0; i<N; i++) {
    cin >> num;
    if (isPrimeNumber(num)) counter++;
  }
  
  cout << counter << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int N,M;
int cnt[222222];

signed main(){
    cin>>N>>M;
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        cnt[a]++;cnt[b]++;
    }

    rep(i,N){
        if(cnt[i]%2==1){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

struct Node{
    int key;
    struct Node* left, *right;
};
struct Node* newNode(int key){
   struct Node* node=new Node;
   node->key=key;
   node->left=node->right=nullptr;
   return node;
};
void inorder(struct Node* root){
  if(root==nullptr){
      return;
  }
  cout << root->key << " ";
  inorder(root->left);
  inorder(root->right);
}

void inputTree(struct Node*& root,int n){

    struct Node* parent, *child;
    map<int,struct Node*> mp;
    int n1,n2;
    char lr;
    while(n--){
        cin >> n1 >> n2 >> lr;
        if(mp.find(n1)==mp.end()){
           parent=newNode(n1);
           mp[n1]=parent;
           if(root==nullptr){
              root=parent;
           }
        }else{
          parent=mp[n1];
        }

        child=newNode(n2);
        if(lr=='L'){
           parent->left=child;
        }else{
           parent->right=child;
        }
        mp[n2]=child;
    }
}

bool cmp(pii a,pii b)
{
    return a.f<b.f;
}

int n,a,b;


int main(){
  cin >> n >> a >> b;
  cout << min(a*n,b);
  return 0;
}


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

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

int main() {
    ll K, S; cin >> K >> S;

    ll ans = 0;
    for(ll i = 0; i <= K; i++){
        for(ll j = 0; j <= K; j++){
            ll sum = S - i - j;
            if(0 <= sum && sum <= K) ans++;
        }
    }
    cout << ans << endl;
}


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 rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, ans;
  cin >> n >> ans;
  rep(i, n - 1) {
    int a;
    cin >> a;
    ans = __gcd(ans, a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	nums := make([]int, n)
	for i := range nums {
		fmt.Scanf("%d", &nums[i])
	}

	sum := float64(0)
	for _, v := range nums {
		sum += float64(v)
	}
	border := sum / float64(4*m)

	countOK := 0
	for _, v := range nums {
		if border <= float64(v) {
			countOK++
			if countOK == m {
				break
			}
		}
	}

	if m <= countOK {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
	int N,K;
	scanf("%d%d",&N,&K);
	int a,b;
	double p[N];
	double sum=0;
	for(a=1;a<=N;a++){
		p[a-1]=1;
		b=a;
		while(b<K){
			p[a-1]=p[a-1]*0.5;
			b=b*2;
		}
		sum=sum+p[a-1];
	}
	double per;
	per=sum/N;
	printf("%.9le",per);
return 0;
}

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

int main() {
  string src;
  string target;
  getline(cin, src);
  getline(cin, target);

  int result = 0;
  for (int i = 0; i < src.length(); i++) {
    if (src.at(i) != target.at(i)) {
      result++;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3900
#C
N = int(input())
XYH = [list(map(int,input().split())) for i in range(N)]

CX = 0
CY = 0
flag = 0
for CX in range(101):
    for CY in range(101):
        H = 0
        hmax = -1
        for i in range(N):
            x,y,h = XYH[i]
            if H == 0:
                if h != 0:
                    H = abs(CX-x)+abs(CY-y)+h
                    if H > hmax and hmax >= 0:
                        H = 0
                        break
                else:
                    hmax = max(hmax,abs(CX-x)+abs(CY-y)+h)
            else:
                if h != 0:
                    if H != abs(CX-x)+abs(CY-y)+h:
                        H = 0
                        break
                else:
                    if H > abs(CX-x)+abs(CY-y)+h:
                        H = 0
                        break
        if H >= 1:
            print(CX,CY,H)
            flag = 1
            break
    if flag == 1:
        break
            



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
//const ll INF=1LL<<60;

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll H,W;cin>>H>>W;
    if(H==1||W==1) cout<<1<<endl;
    else if((H*W)%2){
        cout<<(H*W)/2+1<<endl;
    }else{
        cout<<H*W/2<<endl;
    }
}



Measured memory_bytes: 256
var N,i,P,ans:Longint;A:Array[1..100]of Longint;
begin
read(N);
P:=1;
for i:=1 to N do begin
read(A[i]);
if A[P]<>A[i]then begin
inc(ans,(i-P)div 2);
P:=i;
end;
end;
writeln(ans+(N+1-P)div 2);
end.

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
int p[252521];
vi ch[252521];
int val[252521];
bool cycled[252521];

pii calc(int x){
  set<int> S;
  for(int to : ch[x]){
    S.insert(val[to]);
  }
  int a=-1, b=-1;
  REP(i,1000){
    if(S.count(i)==0){
      if(a==-1)a=i;
      else{
        b=i;break;
      }
    }
  }
  return pii(a,b);
}

bool solve(){
  REP(i,n)val[i]=-1;
  REP(i,n)cycled[i]=false;

  int it = 0;
  REP(i,n)it = p[it];
  vi cycle;
  while(true){
    cycle.push_back(it);
    cycled[it] = true;
    it = p[it];
    if(cycle.front() == it)break;
  }
  int m = cycle.size();
  vi order;
  REP(i,m){
    for(int to : ch[cycle[i]])if(!cycled[to]){
      stack<int> S;
      S.push(to);
      while(S.size()){
        int x = S.top(); S.pop();
        for(int to : ch[x])if(!cycled[to]){
          S.push(to);
        }
        order.push_back(x);
      }
    }
  }
  reverse(ALL(order));
  REP(i,n)val[i]=-1;
  for(int x : order){
    val[x] = calc(x).first;
  }
  pii cand = calc(cycle.front());
  vi CCC;
  CCC.push_back(cand.first);
  CCC.push_back(cand.second);
  for(int c : CCC){
    val[cycle[0]] = c;
    for(int p : cycle){
      if(p==cycle[0])continue;
      val[p] = calc(p).first;
    }
    int ooo = calc(cycle[0]).first;
    if(c==ooo){
      return true;
    }
  }
  return false;
}

int main(){
  #if 1
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",p+i);
    p[i]--;
    ch[p[i]].push_back(i);
  }
  puts(solve() ? "POSSIBLE" : "IMPOSSIBLE");
  #else
  while(true){
    n = 5;
    REP(i,n)ch[i].clear();
    REP(i,n){
      p[i] = i==0 ? (rand()%(n-1)+1) : (rand()%i);
      ch[p[i]].push_back(i);
    }
    if(solve()){
      REP(i,n)if(calc(i).first!=val[i]){
        REP(j,n)printf("%3d,",p[j]);puts("");
        REP(j,n){
          printf("val %d , calc %d\n",val[j],calc(j).first);
        }
        return 0;
      }
    }
  }
  #endif
  return 0;
}


Measured memory_bytes: 14328
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

int main() {
	int a = 0, b = 0, c = 0, x = 0;
	std::cin >> a >> b >> x;
	for (int i = 0; i <= b; i++) {
		if (a + i == x) {
			std::cout << "YES" << std::endl;
			return 0;
		}
	}
	std::cout << "NO" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

int main() {
    int H, W;  cin >> H >> W;
    char a[H][W];  
    rep(i, H) {
        rep(j, W) {
            cin >> a[i][j];
        }
    }

    char b[H+2][W+2];
    rep(i, H+2) {
        rep(j, W+2) {
            b[i][j] = '#';
        }
    }
    rep(i, H) {
        rep(j, W) {
            b[i+1][j+1] = a[i][j];
        }
    }

    rep(i, H+2) {
        rep(j, W+2) {
            cout << b[i][j];
        }
        cout << endl;
    }
}




Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cksharma
 */

#include <bits/stdc++.h>
using namespace std;

class ABulletinBoard {
public:
    void solve(istream& cin, ostream& cout) {
        ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
        cout.setf(ios::fixed); cout.precision(20);
        int N, H, W; cin >> N >> H >> W;
        cout << (N - H + 1)*(N - W + 1) << endl;
    }
};


int main() {
    ABulletinBoard solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		if (N*500>=M) {
			System.out.println("Yes");
		} else {
			System.out.println("No ");
		}
	}
}

Measured memory_bytes: 20820
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    rep(i,100){
        if(n==0){
            cout << i << endl;
            return 0;
        }
        n /=k;
    }
    return 0;
}

Measured memory_bytes: 256
import array
import collections
import heapq
 
 
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1
 
 
# Prim?????§??????0?????????????°???¨?????¨????±???????
def compute_mst_prim(max_v, adj_list):
    # pred[u]?????????u???????????¨???????????????????????¨???
    pred = collections.defaultdict(lambda: NO_VERTEX)
    # u??¨pred[u]????????¶???????????????key[u]?????\???
    key = collections.defaultdict(lambda: INF)
    key[0] = 0
    # ??????????????????????????????????????\?????¨????????¨??????
    pq = [(key[v], v) for v in range(max_v)]
    heapq.heapify(pq)
    # ????????????????????\?????????????????\??£???????????????????????????
    in_pq = array.array("B", (True for _ in range(max_v)))
    while pq:
        _, u = heapq.heappop(pq)
        in_pq[u] = False
        for v, v_cost in adj_list[u]:
            if in_pq[v]:
                weight = v_cost
                if weight < key[v]:
                    pred[v] = u
                    key[v] = weight
                    heapq.heappush(pq, (weight, v))
                    in_pq[v] = True
    return (pred, key)
 
 
def main():
    max_v, max_e = map(int, input().split())
    adjacency_list = collections.defaultdict(set)
    for _ in range(max_e):
        s, t, w = map(int, input().split())
        adjacency_list[s].add(AdjacentVertex(t, w))
        adjacency_list[t].add(AdjacentVertex(s, w))
    (_, key) = compute_mst_prim(max_v, adjacency_list)
    print(sum(key.values()))
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 49960
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int N = 0;
        int S = 0;
        int E = 0;
        int W = 0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='N') N = N|1;
            if(s.charAt(i)=='E') E = E|1;
            if(s.charAt(i)=='S') S = S|1;
            if(s.charAt(i)=='W') W = W|1;
        }
        int flag1 = N^S;
        int flag2 = E^W;
        String ans = (flag1==0&&flag2==0)?"Yes":"No";
        System.out.println(ans);
    }
}


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

int main() {
  int akun, bkun;

  cin >> akun >> bkun;

  if(akun > 8 || bkun > 8) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }

  return 0;
}


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

 
int main()
{
    int N;
    int d[101]={};
    int i,j;
    int min=101;
    int e_cnt=0;
  
 // 整数の入力
    scanf("%d", &N);
 // printf("%d\n",N);
    for(i=0;i<N;i++){
      scanf("%d", &d[i]);
        for(j=0;j<i;j++){
          if(d[i]==d[j]){
            e_cnt++;
            break;
          }
        }
    }
        
    printf("%d\n", N - e_cnt);
    return 0;
}


Measured memory_bytes: 256
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
using System.IO;
using System.Text;

//============================================================================
namespace Sweet
{
    class Program
    {
        static StreamWriter writer = null;

        //============================================================================
        static void setstdio(string[] args)
        {
            if (0 < args.Length)
            {
                // Redirect standard input from the console to the input file.
                Console.SetIn(new StreamReader(args[0]));
                if (args.Length == 2)
                {
                    // Attempt to open output file.
                    writer = new StreamWriter(args[1]);
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);
                }
            }

        }
        //============================================================================
        static void fillmatrix(uint m, uint n, Int64[,] ary)
        {
            int i, j,a;

            for (i = 0; i < m; i++)
            {
                string str = Console.ReadLine();
                for (j = 0; j < n; j++)
                {
                    a = str.IndexOf(" ");
                    if (0 <= a)
                    {
                        ary[i, j] = uint.Parse(str.Substring(0, a));
                        str = str.Substring(a + 1);
                    }
                    else
                        ary[i, j] = uint.Parse(str.Substring(0));
                }
            }
        }
        //============================================================================
        //============================================================================
        private static void Swing()
        {
            StringBuilder builder = new StringBuilder(Console.ReadLine());
            for (int i = 0; i < builder.Length; i++)
                if ('A' <= builder[i] && builder[i] <= 'Z' || 'a' <= builder[i] && builder[i] <= 'z')
                    builder[i] = (char)(builder[i] ^ ' ');
            Console.WriteLine(builder);
        }
        //============================================================================
        static void Main(string[] args)
        {
            setstdio(args);

            Swing();
            if (writer != null)
                writer.Close();
            //Console.ReadLine();
        }
        //============================================================================
    }
}

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

int main(){
	int k,a,b;
	cin>>k>>a>>b;
	
	int cnt=0;
	for(int i=a; i<=b; i++){
		if(i%k==0) cnt++;
	}
	if(cnt==0) cout<<"NG"<<endl;
	else cout<<"OK"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N, K;
  cin >> N >> K;

  vll V(N);
  rep(i, N) {
    cin >> V[i];
  }

  ll ans = 0;

  rep(i, K + 1) {  // i個取る時
    if (i > N) {
      continue;
    }

    rep(j, i + 1) {  // 左から取る数
      vll box;
      ll sum = 0;
      rep(p, j) {  // 左から取る
        box.pb(V[p]);
        sum += V[p];
      }

      rep(k, i - j) {  // 右から取る
        ll index = V.size() - 1 - k;
        box.pb(V[index]);
        sum += V[index];
      }
      SORT(box);
      // debug(i);
      // debug(j);
      // debugV(box);
      // ENDL;

      ll count = 0;
      rep(q, box.size()) {
        if (count == K - i) break;
        if (box[q] < 0) {
          sum -= box[q];
          count++;
        } else {
          break;
        }
      }

      ans = max(ans, sum);
    }
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 3644
<?php
  $t1 = 0;
  $t2 = 0;
  $t3 = 0;
  while($i=(int)fgets(STDIN)) {
      if($i>$t3) {
          if($i>$t2) {
              if($i>$t1) {
                  $t3 = $t2;
                  $t2 = $t1;
                  $t1 = $i;
              } else {
                  $t3 = $t2;
                  $t2 = $i;
              }
          } else {
              $t3 = $i;
          }
      }
  }
  echo $t1."\n";
  echo $t2."\n";
  echo $t3."\n";

Measured memory_bytes: 15332
#ITP1_7_B
m=int(0)
while True:
  m=0
  n,x=map(int,input().split())
  if n ==0 and x==0:
    break
  for a in range(1,n-1):
    for b in range(a+1,n):
      for c in range(b+1,n+1):
        if a+b+c==x:
          m=m+1
  print(m)


Measured memory_bytes: 5596
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll n,m,a;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>n>>m;
	ll sum=0;
	while(m--)
	{
	    cin>>a;
	    sum+=a;
	}
	cout<<max(-1ll,n-sum);
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector <int> a = vector <int> (n);
  int m=0;
  int zero =0;
  long long ans =0;
  const int INF = 1001001001;
  
  //入力と、マイナスの数を数える
  for(int i=0; i <n; i++){
    cin>> a.at(i);
    ans+=std::abs(a.at(i));
    if(a.at(i) < 0){
        m++;
    } else if(a.at(i) == 0){
        zero = -1;
    }
  }
  int mini = INF;
  for(int i =0; i < n; i ++){
      mini = min(mini,std::abs(a.at(i)));
  }
 


  if(zero == -1||m%2==0){

    cout << ans<<endl;
  }else {
cout << ans -2*mini << endl;
  }
}


Measured memory_bytes: 640
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		t, d, l := io.NextInt(), io.NextInt(), io.NextInt()
		if t == 0 {
			break
		}
		cnt := 0
		elapsed := math.MaxInt32
		for i := 0; i < t-1; i++ {
			x := io.NextInt()
			if x >= l {
				cnt++
				elapsed = 1
			} else if elapsed < d {
				cnt++
				elapsed++
			}
		}
		_ = io.NextInt()
		io.Println(cnt)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 6300
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1005;
const int Mo = 1e9 + 7;

int ans, n;
bool flag[MAXN];

int calc(int p) {
	int num = 1;
	for (int now = p; now <= n; now *= p)
		num += n / now;
	return num;
}

int main() {
	scanf("%d", &n);
	ans = 1;
	for (int i = 2; i <= n; i ++) {
		if (flag[i]) continue;
		ans = 1ll * ans * calc(i) % Mo;
		for (int j = i; j <= n; j += i) flag[j] = 1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll p;
    cin >> n >> p;
    ll i=2;
    ll ans=1;
    if(n==1){
        ans=p;
    }else if(n>=p){
        ans=1;
    }else if(n>=40){
        ans = 1;
    }else{
        //ll a=p/n+1;
        while(i*i<=p){
            ll t=i;
            REP(j,n-1){
                t*=i;
            }
            if(t>p){
                break;
            }
            if(p%t==0){
                ans = i;
                //break;
            }
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int h, w, black = 0, mv[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
    scanf("%d %d", &h, &w);
    vector<vector<char>> a(h + 2, vector<char>(w + 2, '#'));
    for (int i = 1; i <= h; ++i)
    {
        scanf("\n");
        for (int j = 1; j <= w; ++j)
        {
            scanf("%c", &a[i][j]);
            black += a[i][j] == '#';
        }
    }
    queue<pair<int, pair<int, int>>> q;
    vector<vector<bool>> vis(h + 2, vector<bool>(w + 2, false));
    q.push(make_pair(0, make_pair(1, 1)));
    vis[1][1] = true;
    for (int t, x, y; !q.empty(); )
    {
        t = q.front().first;
        x = q.front().second.first;
        y = q.front().second.second;
        q.pop();
        if (x == h && y == w)
        {
            printf("%d\n", h * w - black - t - 1);
            return 0;
        }
        for (int i = 0; i < 4; ++i)
        {
            if (a[x + mv[i][0]][y + mv[i][1]] == '.' && !vis[x + mv[i][0]][y + mv[i][1]])
            {
                vis[x + mv[i][0]][y + mv[i][1]] = true;
                q.push(make_pair(t + 1, make_pair(x + mv[i][0], y + mv[i][1])));
            }
        }
    }
    printf("-1\n");
    return 0;
}



Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define INF 10000000000000000
int q,h,s,d;
//ll dp[9];
ll  solve(double x)
{
  if(x==0.0)
   return 0;
  else if(x<0)
   return INF;
   /*if(dp[4*(int)x]!=-1)
    return dp[4*(int)x];*/
  return  min(q+solve(x-0.25),min(h+solve(x-0.5),min(s+solve(x-1.0),d+solve(x-2.0))));
}

int main()
{
 //memset(dp,-1,sizeof dp);
  cin >> q >> h >> s >> d;
  int n;
  cin >> n;
  ll a=solve((double)1.0);
  ll b=solve((double)2.0);
  //cout << a<<" "<<b<<"\n";
  int d_amt=(n/2);
  ll ans_2=(d_amt*b);
  int left=(n-(d_amt*2));
  ll ans_1=(left*a);
  //cout << d_amt<<" "<<ans_2<<" "<<left<<" "<<ans_1<<"\n";
  cout << (ans_1+ans_2);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int main (int argc, char* argv[]) {
	string s, t;
	cin >> s >> t;

	vector<vector<int>> c_pos(26);
	for (int i = 0; i < s.size(); i++) {
		c_pos[s[i] - 'a'].push_back(i);
	}

	long long res = (long long)s.size() - 1;
	for (int i = 0; i < t.size(); i++) {
		const auto& pos = c_pos[t[i] - 'a'];
		if (pos.empty()) {
			cout << -1 << endl;
			return 0;
		}
		auto next_pos_min = (res + 1) % s.size();
		auto next_pos_itr = lower_bound(pos.begin(), pos.end(), next_pos_min);
		if (next_pos_itr == pos.end()) {
			// not found
			res += s.size() - (res % s.size());
			res += pos[0];
		} else {
			// found
			res += *next_pos_itr - ((res + 1) % s.size()) + 1;
		}
	}
	cout << res - (long long)s.size() + 1 << endl;
}


Measured memory_bytes: 1216
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	long long s, tmp = 0,minNum = 100000000;
	cin >> s;
	while(s!=0){
		tmp = abs(s % 1000 - 753);
		minNum = min(minNum,tmp);
		s /= 10;
	}
	cout << minNum << endl;
}


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


template<typename T> 
struct BIT{
  Int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(Int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(Int i){
    T s=bit[0];
    for(Int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(Int i,T a){
    if(i==0) return;
    for(Int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  
  Int lower_bound(Int w){
    if(w<=0) return 0;
    Int x=0,r=1;
    while(r<n) r<<=1;
    for(Int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x+1;
  }
  
  T sum0(Int i){
    return sum(i+1);
  }
  void add0(Int i,T a){
    add(i+1,a);
  }

  T query(Int l,Int r){
    return sum(r-1)-sum(l-1);
  }

  T query0(Int l,Int r){
    return sum(r)-sum(l);
  }
};


template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> p(n),l(n);
  for(Int i=0;i<n;i++) cin>>p[i];
  for(Int i=0;i<n;i++) cin>>l[i];

  vector<Int> a(p);
  for(Int i=1;i<n;i++) a[i]+=a[i-1];
  vector<Int> b(a);
  sort(a.begin(),a.end()-1);
  auto NG=[](){cout<<-1<<endl;exit(0);};
  if(a[0]<l[0]) NG();
  for(Int i=1;i<n;i++)
    if(a[i]-a[i-1]<l[i]) NG();

  a=compress(a);
  auto m=dict(a);
  BIT<Int> bit(n,0);
  Int ans=0;
  for(Int i=0;i<n;i++){
    ans+=i-bit.sum0(m[b[i]]);
    bit.add0(m[b[i]],1);    
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 12892
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

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

	int N;
	cin >> N;
	vector<array<int, 2>>v(N);
	rep(i, N)cin >> v[i][0] >> v[i][1];

	REP(i, 1, N) {
		int x0 = (v[i - 1][0] + v[i][0] - 1) / v[i][0];
		int x1 = (v[i - 1][1] + v[i][1] - 1) / v[i][1];
		int x = max(x0, x1);
		v[i][0] *= x;
		v[i][1] *= x;
	}
	cout << v[N - 1][0] + v[N - 1][1] << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vecx(N);
  vector<int> vecy(N);
  vector<int> vech(N);
  for(int i=0;i<N;i++){
    cin >> vecx.at(i) >> vecy.at(i) >> vech.at(i);
  }
  
  for(int k=0; k<N; k++){
    if(vech.at(k) > 0){
      for(int i=0; i<=100; i++){ 
        for(int j=0; j<=100; j++){
          int H = vech.at(k) + abs(vecx.at(k)-i) + abs(vecy.at(k)-j);
          bool flag = true;
          for(int l=0; l<N; l++){
            if(vech.at(l) != max(H-abs(vecx.at(l)-i)-abs(vecy.at(l)-j),0)){
              flag = false;
            }
          }
          if(flag){
            cout << i << " " << j << " " << H << endl;
            return 0;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    s=input()
    cunt=0
    for i in range(n-1):
        if s[i]!=s[i+1]:
            cunt+=1
    print(n-1-cunt+min(2*k,cunt))

if __name__=='__main__':
    main()

Measured memory_bytes: 39280
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
#include <fstream>
#include<set>
//AtCoderC++.cpp

using namespace std;

template<typename T>
inline T ceiling(T n, T d) {
	return n % d == 0 ? n / d : n / d + 1;
}


int main() {
	int N; cin >> N;
	auto vs = vector<int>(N);
	for (size_t i = 0; i < N; i++) cin >> vs[i];
	sort(vs.begin(), vs.end());
	double answer = vs[0];
	for (size_t i = 1; i < N; i++) {
		answer = (answer + vs[i]) / 2;
	}
	cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n;
	long long int cnt = 0;
	long long int mx = 0;

	cin >> n;
	int a;
	cin >> a;
	cnt = a - 1;
	mx = 1;
	for (int i = 1; i < n; i++) {
		cin >> a;
		if (a <= mx) {
			continue;
		}
		else if (a == mx + 1) {
			mx = a;
			continue;
		}

		int c = (a) / (mx + 1);
		if ((a) % (mx + 1) == 0) {
			c--;
		}
		cnt += c;
	}

	cout << cnt << endl;
}


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

using namespace std;

int main(){
	
	int n;
	
	cin >> n;
	
	string u[n];
	
	for(int i=0;i<n;i++){
		cin >> u[i];
	}
	
	int m;
	
	bool open=false;
	
	cin >> m;
	
	for(int i=0;i<m;i++){
		string t;
		cin >> t;
		
		for(int j=0;j<=n;j++){
			if(j==n){
				cout << "Unknown " << t << endl;
			}
			if(u[j]==t){
				if(open==true){
					cout << "Closed by " << t << endl;
					open=false;
				}else{
					cout << "Opened by " << t << endl;
					open = true;
				}
				break;
			}
		}
	}
					
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define enum(i,x,y) for(int i=(x);i<=(y);++i)
#define try(i,x,y) for(int i=(x);i>=(y);--i)
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=1005;

int n,m,a,b;
char s[MAXN][MAXN];
void chara(int i,int j)
{
	if(a>0)
	{
		a-=2;
		s[i][j]='<',s[i][j+1]='>';
		s[i+1][j]=(a>=0?'<':'.'),s[i+1][j+1]=(a>=0?'>':'.');
		if(a<0)a=0;
	}
	else if(b>0)
	{
		b-=2;
		s[i][j]='^',s[i][j+1]=(b>=0?'^':'.');
		s[i+1][j]='v',s[i+1][j+1]=(b>=0?'v':'.');
		if(b<0)b=0;
	}
	else s[i][j]=s[i][j+1]=s[i+1][j]=s[i+1][j+1]='.';
}
bool work(int n,int m)
{
	if(2*(a+b)==n*m && (a&1))return 0;
	enum(i,1,n/2)
		enum(j,1,m/2)
			chara(i*2-1,j*2-1);
	if(a!=0 || b!=0)return 0;
	return 1;
}
void print()
{
	printf("YES\n");
	enum(i,1,n)
	{
		enum(j,1,m)
			putchar(s[i][j]);
		putchar('\n');
	}
}
void solve()
{
	s[n-2][m-2]='<';s[n-2][m-1]='>';s[n-2][m]='^';
	s[n-1][m-2]='^';s[n-1][m-1]='.';s[n-1][m]='v';
	s[n][m-2]='v';s[n][m-1]='<';s[n][m]='>';
	a-=2;b-=2;
	enum(i,1,(m-3)/2){s[n][i*2-1]='<';s[n][i*2]='>';--a;}
	enum(i,1,(n-3)/2){s[i*2-1][m]='^';s[i*2][m]='v';--b;}
	enum(i,1,(n-1)/2)
		enum(j,1,(m-1)/2)
			if(i!=(n-1)/2 || j!=(m-1)/2)chara(i*2-1,j*2-1);
	if(a!=0 || b!=0){printf("NO\n");exit(0);}
}

int main()
{
	readint(n);readint(m);readint(a);readint(b);
	int ta=a,tb=b;
	if((a+b)*2>n*m)return 0*printf("NO\n");
	s[n][m]='.';
	if(n&1)
	{
		enum(i,1,m/2)
			if(a>0){--a;s[n][i*2-1]='<';s[n][i*2]='>';}
			else s[n][i*2-1]=s[n][i*2]='.';
	}
	if(m&1)
	{
		enum(i,1,n/2)
			if(b>0){--b;s[i*2-1][m]='^';s[i*2][m]='v';}
			else s[i*2-1][m]=s[i*2][m]='.';
	}
	if(work(n/2*2,m/2*2))print();
	else if((n&1) && (m&1) && n>1 && m>1){a=ta;b=tb;solve();print();}
	else printf("NO\n");
    return 0;
}

Measured memory_bytes: 2176
import Data.List
import Control.Applicative
import Control.Monad

main = do
    n <- readLn :: IO Int
    cards <- forM [1..n] $ \i -> do
                    c <- words <$> getLine
                    let cType = c !! 0
                        cNum  = read (c !! 1) :: Int
                    return $ Card cType cNum
    let diff = defaultCards \\ cards
    forM_ diff $ \c -> do
        putStrLn $ cardType c ++ " " ++ (show $ cardNum c)


data Card = Card { cardType :: String
                 , cardNum  :: Int
                 } deriving (Show, Eq)
type Cards = [Card]

defaultCards = [ Card "S" 1
               , Card "S" 2
               , Card "S" 3
               , Card "S" 4
               , Card "S" 5
               , Card "S" 6
               , Card "S" 7
               , Card "S" 8
               , Card "S" 9
               , Card "S" 10
               , Card "S" 11
               , Card "S" 12
               , Card "S" 13
               , Card "H" 1
               , Card "H" 2
               , Card "H" 3
               , Card "H" 4
               , Card "H" 5
               , Card "H" 6
               , Card "H" 7
               , Card "H" 8
               , Card "H" 9
               , Card "H" 10
               , Card "H" 11
               , Card "H" 12
               , Card "H" 13
               , Card "C" 1
               , Card "C" 2
               , Card "C" 3
               , Card "C" 4
               , Card "C" 5
               , Card "C" 6
               , Card "C" 7
               , Card "C" 8
               , Card "C" 9
               , Card "C" 10
               , Card "C" 11
               , Card "C" 12
               , Card "C" 13
               , Card "D" 1
               , Card "D" 2
               , Card "D" 3
               , Card "D" 4
               , Card "D" 5
               , Card "D" 6
               , Card "D" 7
               , Card "D" 8
               , Card "D" 9
               , Card "D" 10
               , Card "D" 11
               , Card "D" 12
               , Card "D" 13 ]

Measured memory_bytes: 4076
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s.size() == 2) {
		cout << s << endl;
	}
	else {
		cout << s[2] << s[1] << s[0] << endl;
	}
}









Measured memory_bytes: 768
# 上位ノードほど @rank が大きい数字となる
class Node
  attr_accessor :parent, :rank

  # 親は自分自身、ランクは 0 として初期化する
  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFind
  # 0 から n までのノード（つまりn + 1個）を初期化する
  def initialize(n)
    @nodes = (0..n).map { |i| Node.new(i) }
  end

  # 再帰で最も上位の親を探して更新し、その値を返す
  def parent(x)
    return x if @nodes[x].parent == x
    return @nodes[x].parent = parent(@nodes[x].parent)
  end

  # a と b を仲間にする
  def unite(a, b)
    a_parent = parent(a)
    b_parent = parent(b)
    # a 及び b の親が同じ場合は何もしない
    return if a_parent == b_parent

    # a親ランク < b親ランク の場合は、b親をa親の親とする
    # なお、ランクをいじる必要はなし
    if @nodes[a_parent].rank < @nodes[b_parent].rank
      @nodes[a_parent].parent = b_parent
    # その他の場合は、a親をb親の親とする
    else
      @nodes[b_parent].parent = a_parent
    # a親、及びb親のランクが同じ場合は、a親のランクを +1 する
      @nodes[a_parent].rank += 1 if @nodes[a_parent].rank == @nodes[b_parent].rank
    end
  end

  # a と b の親が同じかどうかを返す
  def same?(a, b)
    parent(a) == parent(b)
  end

  # 各ノードの親を全て出力する確認用
  def parents
    @nodes.map(&:parent)
  end
end

n, m = gets.split.map(&:to_i)
edges = []
m.times { edges << gets.split.map(&:to_i) }
sum = 0
edges.each do |edge1|
  tree = UnionFind.new(n)
  edges.each do |edge2|
    if edge1 == edge2
      next
    else
      tree.unite(edge2[0], edge2[1])
    end
  end
  sum += 1 unless tree.same?(edge1[0], edge1[1])
end
puts sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x21 = x2 - x1;
  int y21 = y2 - y1;
  int y3 = y2 + x21;
  int x3 = x2 - y21;
  int x4 = x3 - x21;
  int y4 = y3 - y21;
  printf("%d %d %d %d\n", x3, y3, x4, y4);
}

Measured memory_bytes: 256
def print_ans(l,r,N):
  """print(sum(r)-sum(l)+N)
  Parameters
  --------------
  >>> print_ans([24],[30],1)
  7
  >>> print_ans([6,3],[8,3],2) 
  4
  """
  print(sum(r)-sum(l)+N)


  

def main():
  N = int(input())
  l = []
  r = []
  for i in range(N):
    s = list(map(int,input().split()))
    l.append(s[0])
    r.append(s[1])

  print_ans(l,r,N)


if __name__ == '__main__':
  main()



Measured memory_bytes: 39408
import sys
input = sys.stdin.readline
n=int(input())
edge=[set() for i in range(n+1)]
for i in range(n-1):
    a,b=[int(j) for j in input().split()]
    edge[a].add(b)
    edge[b].add(a)

c=[int(j) for j in input().split()]
d=[len(i) for i in edge]

d1=[i for i,x in enumerate(d) if x==1]

ans=[None]*(n+1)
c.sort()
c.reverse()
m=sum(c)-c[0]

while d1:
    v=d1.pop()
    if not d1:
        ans[v]=c.pop()
        break
    w=edge[v].pop()
    edge[w].remove(v)
    d[w]-=1
    if d[w]==1:
        d1.append(w)
    ans[v]=c.pop()

print(m)
print(*ans[1:])



Measured memory_bytes: 7316
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int count = 0 ;
  int dotti;
  dotti = max(a,b);

  for(int i=dotti;i>0;i--){
    if(a%i==0 && b%i==0)count++ ;
      if(count == k){
      cout << i << endl;
      return 0;
      }
  }
}


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

int main() {
	int n,x,i, max;  x=0; max=0;
	cin>>n;
	char ch[n+1];
	cin>>ch;
	
	for (i=0 ; i<n; ++i)
	{
	    if (ch[i]=='I')
	    ++x;
	    else if (ch[i]=='D')
	    --x;
	    
	    if (x>max)
	    max = x;
	}
	cout<<max;
	
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

long long gcd(long long a, long long b){
	if(b > a) swap(a, b);
	long long tmp;
	while(b != 0){
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

int main(){
	LL A, B, C, D;
	cin >> A >> B >> C >> D;
	A--;
	LL ans = B-A;
	//cout << ans << endl;
	ans -= B/C;
	ans += A/C;
	//cout << ans << endl;
	ans -= B/D;
	ans += A/D;
	//cout << ans << endl;
	ans += B/(C*D/gcd(C, D));
	ans -= A/(C*D/gcd(C, D));
	cout << ans << endl;
}


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

bool rec(int n, int& k, string& s) {
  if (n == 0) {
    --k;
    return k == 0;
  }
  if (s.empty()) {
    for (int d = 1; d <= 9; ++d) {
      s += '0' + d;
      if (rec(n - 1, k, s)) return true;
      s.pop_back();
    }
  } else {
    for (int d = 0; d <= 9; ++d) {
      int c = s.back() - '0';
      if (abs(d - c) > 1) continue;
      s += '0' + d;
      if (rec(n - 1, k, s)) return true;
      s.pop_back();
    }
  }
  return false;
}

string sub(int k) {
  string s;
  for (int i = 1; i <= 12; ++i) {
    if (rec(i, k, s)) return s;
  }
}

int main() {
  int k;
  cin >> k;
  cout << sub(k) << endl;
}

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

int main() {
  
  int N; cin >> N; int count = 0;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i];
  
  for (int i = 0; i < N; i++) {
    
    if (vec[(vec[i] - 1)] - 1 == i) count++;
    
  }
  
  cout << count / 2 << endl;
  
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll X, N;
  scanf("%lld %lld", &X, &N);

  map<ll, ll> m;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    m[v] = 1;
  }

  ll a;

  ll ans = INF;
  for (ll i = 0; i <= 101; i++) {
    if (!m[i]) {
      ll c = abs(X - i);
      if (c < ans) {
        a = i;
      }
      ans = min(ans, c);
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 3700
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    S=input()
    ans=0
    tmp=0
    for s in S:
        if s=='I':
            tmp+=1
        else:
            tmp-=1
        ans=max(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getc (map (wrds toInt)) >>= putStrLn . unwords . map show

solve :: [[Int]] -> [Int]
solve xs = foldr f [0,0,0,0] xs
  where
    f ys [n,t1,t2,t3]
      | c >= a + b = [0,0,0,0]
      | c ^ 2 == a ^ 2 + b ^ 2 = [n+1,t1+1,t2,t3]
      | c ^ 2 < a ^ 2 + b ^ 2 = [n+1,t1,t2+1,t3]
      | otherwise = [n+1,t1,t2,t3+1]
      where
        [a,b,c] = sort ys
        
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getc :: ([String] -> a) -> IO a
getc f = f . lines <$> getContents

Measured memory_bytes: 4360