akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
A=[0]+list(map(int,input().split()))

color=["white" for _ in range(n+1)]
DP,index=[],1

while 1:
    if color[index]=="white":color[index]="gray"
    elif color[index]=="gray":color[index]="black"
    DP.append(A[index])
    index=A[index]
    if color[index]=="black":break

repeat=[]
for i in DP:
    if color[i]=="black":
        repeat.append(i)
        if repeat[0]==i and len(repeat)!=1:
            repeat.pop()
            break
length=len(repeat)
cnt=0
for i in DP:
    if repeat[0]==i:break
    cnt +=1

if k<=cnt+length:
    print(DP[k-1])
else:
    k -=cnt
    k %=length
    print(repeat[k-1])

Measured memory_bytes: 139592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t;cin>>t;while(t--)
#define f(i,n) for (int i=0;i<n;i++)
#define fa(i,a,b) for (int i=a;i<b;i++)
#define b(i,a,b) for (int i=a;i>=b;i--)
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define fi first    
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<">"<<#x<<" = "<<x<<endl;
// #define MOD 1000000007
#define ce cout<<"\n"

int main()
{
    int k, x;
    cin>>k>>x;
    k = k*500;
    if(k>=x)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

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

int main(){
    int cnt[4] = {};
    int a, b;
    for(int i = 0; i < 3; i++){
        cin >> a >> b;
        a--, b--;
        cnt[a]++, cnt[b]++;
    }
    int odd = 0;
    for(int i = 0; i < 4; i++)  odd += cnt[i]%2;
    if(odd <= 2)    cout << "YES" << endl;
    else            cout << "NO" << endl;
    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[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		// 解法
		// Selection sort, cntは交換回数
		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			int minID = i;
			for (int j = i; j < N; j++) {
				if (A[minID] > A[j]) {
					minID = j;
				}
			}
			if (minID != i) {
				cnt++;
				int w = A[i];
				A[i] = A[minID];
				A[minID] = w;
			}
		}

		for (int i = 0; i < A.length; i++) {
			System.out.print(A[i] + (i != A.length - 1 ? " " : "\n"));
		}
		System.out.println(cnt);

		// 入力の開放
		sc.close();
	}
}



Measured memory_bytes: 26372
import sys
input = sys.stdin.readline


def dijkstra(start, matrix):
    # O(V^2)ダイクストラ
    INF = 10 ** 18
    n = len(matrix)
    used = [False] * n
    # 補給回数: 少ないほうがいい
    # 使用燃料: 少ないほうがいい
    # 補給回数が少ないほうがより嬉しい
    # dist[v] = 補給回数 * (10 ** 15) + 使用燃料
    dist = [INF] * n
    dist[start] = 0
    while True:
        v = -1
        for u in range(n):
            if not used[u] and (v == -1 or dist[u] < dist[v]):
                v = u
        if v == -1:
            break
        used[v] = True
        for nxt_v in range(n):
            tmp = merge(dist[v], matrix[v][nxt_v])
            dist[nxt_v] = min(dist[nxt_v], tmp)
    return dist

def merge(d, cost):
    div_d, mod_d = divmod(d + cost, 10 ** 15)
    if mod_d > l:
        new_d = (div_d + 1) * 10 ** 15 + cost
    else:
        new_d = d + cost
    return new_d


n, m, l = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
INF = 10 ** 18

# 隣接行列
matrix = [[INF] * n for i in range(n)]
for i in range(n):
    matrix[i][i] = 0
for a, b, cost in info:
    a -= 1
    b -= 1
    if cost > l:
        continue
    matrix[a][b] = cost
    matrix[b][a] = cost

ans = [[0] * n for i in range(n)] 
for i in range(n):
    tmp = dijkstra(i, matrix)
    for j in range(n):
        ans[i][j] = tmp[j] // (10 ** 15)

for a, b in query:
    a -= 1
    b -= 1
    if ans[a][b] == 1000:
        print(-1)
    else:
        print(ans[a][b])

Measured memory_bytes: 77532
import numpy as np
MaxW=int(1e5)
N,W=map(int,input().split())
WV=[]
for i in range(N):
    WV.append(list(map(int,input().split())))
dp=[1e30 for i in range(MaxW+1)]
dp[0]=0
dp=np.array(dp)
for i in range(N):
    dp[WV[i][1]:]=np.minimum(dp[WV[i][1]:],dp[:MaxW-WV[i][1]+1]+WV[i][0])
for i in reversed(range(MaxW+1)):
    if dp[i]<=W:
        print(i)
        break
        

Measured memory_bytes: 14988
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var rCounter = 0
    var lCounter = 0

    for (c in s) {
        if (c == '(') {
            rCounter++
            continue
        }

        if (rCounter > 0) {
            rCounter--
            continue
        }

        lCounter++
    }

    println("(".repeat(lCounter) + s + ")".repeat(rCounter))
}


Measured memory_bytes: 33916
#include <cstring>
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N,M;
cin>>N>>M;
long long a;
if(N>=3&&M>=3){
a=(M-2)*(N-2);}
else if(M==2||N==2){
a=0;}
else if(N==1&&M==1){
a=1;}
else if(N==1){
a=M-2;}
else if(M==1){
a=N-2;}

cout<<a<<endl;}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Node {int a,b;}v[200100];int n,T,tot;
inline int cmp(const Node &a,const Node &b){return 1ll*b.a*(a.b+1)<1ll*a.a*(b.b+1);}
vector<int> V;
long long f[101],g[101];
int main()
{
	cin>>n>>T;
	for(int i=1;i<=n;i++)
	{
		Node now;scanf("%d%d",&now.a,&now.b);
		if(now.a==0) V.push_back(now.b+1);
		else v[++tot]=now;
	}
	sort(v+1,v+tot+1,cmp);sort(V.begin(),V.end());
	for(int i=1;i<100;i++) f[i]=T+1;
	f[0]=0;
	for(int i=1;i<=tot;i++)
	{
		for(int j=0;j<100;j++) g[j]=f[j];
		for(int j=0;j+1<100;j++)
		{
			long long cal=1ll*(f[j]+1)*(v[i].a+1)+v[i].b;
			g[j+1]=min(g[j+1],cal);
		}
		for(int j=0;j<100;j++) f[j]=g[j];
	}
	int ans=0;
	for(int i=0;i<100;i++) if(f[i]<=T)
	{
		ans=max(ans,i);
		long long nows=0;
		for(int j=0;j<(int)V.size();j++)
		{
			if(nows+f[i]+V[j]>T) break;
			nows+=V[j];ans=max(ans,i+j+1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define ll long long
#define PI 2 * acos(0)
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define MAX 200000
#define MOD 1e7
#define print(a, b) printf("Case %d: %.0f\n", a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
/*................OMI.................*/

bool isPrime(ll n)
{
   if (n <= 1)
      return false;
   if (n <= 3)
      return true;

   if (n % 2 == 0 || n % 3 == 0)
      return false;

   for (ll i = 5; i * i <= n; i = i + 2)
      if (n % i == 0)
         return false;

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

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

///palindrome check!
bool palindrome(string s)
{
   for (ll i = 0; i < s.length() / 2; i++)
   {
      if (s[i] != s[s.length() - i - 1])
         return 0;
   }
   return 1;
}
/// divisors->>
void printDivisors(int n)
{
   for (int i = 1; i <= sqrt(n); i++)
   {
      if (n % i == 0)
      {
         if (n / i == i)
            printf("%d ", i);

         else
            printf("%d %d ", i, n / i);
      }
   }
}

///prime storage>>>

vector<ll> prime;

void primes(ll m)
{

   bool isprime[m];
   for (int i = 0; i <= m; i++)
      isprime[i] = true;

   for (int i = 3; i * i <= m; i++)
   {
      if (isprime[i])
      {

         for (int j = i * i; j <= m; j += i)
            isprime[j] = false;
      }
   }
   prime.push_back(2);
   for (int i = 3; i <= m; i += 2)
      if (isprime[i])
         prime.push_back(i);
}

vector<int> G[MAX];
bool visited[100007];
int ara[10000];
int DFS(int source)
{

   for (int i = 0; i < G[source].size(); i++)
      ara[source] = ara[source] + DFS(G[source][i]);

   return ara[source] + 1;
}

/************MAIN_FUNCTION***********/

int main(int argc, char *argv[])
{
   FAST;
   string s;
   cin >> s;
   if (s == "ABC")
      cout << "ARC" << endl;

   if (s == "ARC")
      cout << "ABC" << endl;
   return 0;
}

Measured memory_bytes: 8364
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!
    val h = (1 until n).filter { s[it] == s[it - 1] }.count()
    println(Math.min(h + 2 * k, n - 1))
}


Measured memory_bytes: 41476
import sys
input = sys.stdin.readline
from collections import Counter

N, M, K = map(int, input().split())
friend = [[] for _ in range(N)]
for _ in range(M) :
  a, b = map(int, input().split())
  friend[a - 1].append(b - 1)
  friend[b - 1].append(a - 1)
block = [[] for _ in range(N)]
for _ in range(K) :
  c, d = map(int, input().split())
  block[c - 1].append(d - 1)
  block[d - 1].append(c - 1)
  
visited = [-1] * N
color = 0
for i in range(N) :
  if visited[i] == -1 :
    q = [i]
    visited[i] = color
    while q :
      cur = q.pop()
      for nex in friend[cur] :
        if visited[nex] >= 0 : continue
        visited[nex] = color
        q.append(nex)    
    color += 1
    
cnt = Counter(visited)

ret = []
for i in range(N) :
  s = cnt[visited[i]]
  for j in block[i] :
    if visited[i] == visited[j] :
      s -= 1
  ret.append(s - len(friend[i]) - 1)
  
print(*ret)

Measured memory_bytes: 90156
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  double ans = 0;
  for (int i = 0; i < n; ++i)
  {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY")
      ans += x;
    else
      ans += x * 380000.0;
  }
  cout << fixed << setprecision(8) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC130().Solve130A(new ConsoleInput(Console.In, ' '));
        }
    }
}

namespace AtCoder
{
    class ABC130
    {
        public void Solve130A(ConsoleInput cin)
        {
            var x = cin.ReadInt;
            var a = cin.ReadInt;
            if (x < a)
                WriteLine(0);
            else
                WriteLine(10);
            ReadLine();
        }
    }
}

namespace AtCoder
{
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long
using namespace std;
pair<int,int> a[101];
int f[100006];
int n,w;

main()
{
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    for(int i=1;i<=100005;i++)
        f[i]=-1;
    for(int i=0;i<n;i++)
    {
       //cerr<<a[i].second;
//        cerr<<j<<endl;
        for(int j=100005LL;j>=a[i].second;j--)
        {
            //cout<<j<<endl;
            if(f[j-a[i].second]!=-1)
            {

                if(f[j]==-1) f[j]=f[j-a[i].second]+a[i].first;
                else f[j]=min(f[j-a[i].second]+a[i].first,f[j]);
            }
        }
    }
    for(int i=1e5+1;i>=0;i--)
    {
        if(f[i]<=w&&f[i]!=-1) {cout<<i;return 0;}
    }

    //cout<<f[w];
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdint.h>

#define MOD_VAL ((uint64_t)1000000007)

uint64_t mul_mod(uint64_t a, uint64_t iter, uint64_t mod)
{
    uint64_t tmp = 0;
    for (int i = 0; i < iter; i++) {
        tmp += a;
        tmp %= mod;
    }
    return tmp;
}

uint64_t hoge(uint64_t cnt) {
    uint64_t tmp = 0;
    int32_t pp; /* prev p */
    uint64_t pinc = 0; /* prev inc */
    for (int i = 0; i < cnt; i++) {
        int32_t p;
        uint64_t w;
        uint64_t inc;
        scanf("%d", &p);
        if (i == 0) {
            pp = p;
            continue;
        }
        w = (uint64_t)(p - pp);
#if 0
        if (w >= MOD_VAL / i) { /* assert */
            printf("assertion failed\n");
            printf("w = %u\n", w);
            printf("i = %u\n", i);
            while(1);
        }
        inc = pinc + (uint64_t)i * w;
#endif
        // printf("w * i = %lu\n", w * i);
        // printf("mul_mod(w, i, MOD_VAL) = %lu\n", mul_mod(w, i, MOD_VAL));

        // inc = pinc + mul_mod(w, i, MOD_VAL);
        inc = pinc + (uint64_t)i * w;
        inc %= MOD_VAL;
        tmp += inc;
        tmp %= MOD_VAL;
        /* save as previous value */
        pp = p;
        pinc = inc;
    }
    return (uint64_t)tmp;
}

int main(void)
{
    uint64_t n, m;
    scanf("%lu %lu", &n, &m);
    printf("%lu\n", (hoge(n) * hoge(m)) % MOD_VAL);
    return 0;
}



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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;

    REPS(m, M) {
        REPS(d, D) {
            int d1 = d % 10;
            int d2 = d / 10;

            if (d1 < 2) continue;
            if (d2 < 2) continue;

            if (d1 * d2 == m) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007


//2分岐探索
vector<int> v(100001);

int nibutan(int n,int k){
    int mid=n-1;
    int end=n-1;
    int srt=0;
    int  mmid;
    int res;
    //2分岐
    for(int j=0;;j++){
      mmid=mid;
      res=v[mid];
      if (res<k){
        end=mid;
        mid=srt+(mid-srt)/2;
      }else{
        srt=mid;
        mid=mid+(end-mid)/2;
      }
      if (mmid==mid)break;
      //if (mid==0)break;
    }
    return mid;
}



int main(){
  int n=0;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin>>a[i];
  REP(i,100001) v[i]=-1;
  int w=1,idx;
  v[0]=a[0];

    for(int i=1;i<n;i++){
        idx=nibutan(w+1,a[i])+1;
        if (v[idx-1]<a[i])idx--;
        //cout<<idx<<" "<<v[idx]<<endl;
        for(int j=idx;j>=0;j--){
            if (v[j]<a[i]){
                if (v[j]==-1)w++;
                v[j]=a[i];
                break;
            }
        }
    }
        

    cout<<w<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

int main()
{
//変数定義
int A;
int B;
//char S[101];

//入力
scanf("%d", &A);
scanf("%d", &B);
//スペースの入力
//scanf("%d %d",&A, &B);
//文字列の入力
//scanf("%s",S);

//A,Bの判定
if(A<10 && B<10){
 printf("%d\n",A*B);
}else
 printf("-1\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll res = 0;
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; ++i) {
        if (i%3 == 0) continue;
        if (i%5 == 0) continue;
        res += i;
    }
    cout << res << endl;
}


Measured memory_bytes: 3624
import java.util.HashSet;
import java.util.Set;

public class Main {

  private static void solve() {
    int n = ni();
    Set<String> set = new HashSet<>();
    for (int i = 0; i < n; i++) {
      set.add(next());
    }
    System.out.println(set.size());

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

int main(void){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#define local

#include <bits/stdc++.h>
#define Mfile freopen("1.in","r",stdin);freopen("1.out","w",stdout)
using namespace std;

int main()
{
    #ifdef local
    //Mfile;
    #endif

    int ans[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int a;
    scanf("%d",&a);
    printf("%d",ans[a-1]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

struct Edge {
public:
	int from, to, cost;
	Edge() {}
	Edge(int _from, int _to, int _cost) {
		from = _from;
		to = _to;
		cost = _cost;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<int, int> P;

vll dijkstra(int s, Graph G) {//s=>始点
	priority_queue<P, vector<P>, greater<P> > que;
	vll D(SZ(G), 10e15);
	D[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first)continue;

		for (Edge e : G[v]) {
			if (D[e.to] > D[v] + e.cost) {
				D[e.to] = D[v] + e.cost;
				que.push(P(D[e.to], e.to));
			}
		}
	}
	return D;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	Graph G(N);
	REP(i, N - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back(Edge(a, b, c));
		G[b].push_back(Edge(b, a, c));
	}
	int Q, K;
	cin >> Q >> K;
	K--;
	vll dist = dijkstra(K, G);
	REP(i, Q) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << dist[x] + dist[y] << endl;
	}
	PAU;
	return 0;
}


Measured memory_bytes: 16180
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

score = [0]

for s_test in s:
    scr = 0
    for ss in s:
        if ss == s_test:
            scr += 1
    for tt in t:
        if tt == s_test:
            scr -= 1
    score.append(scr)

ans = max(score)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int N;cin>>N;
	vector<long long>A(N);
	for (int i = 0; i < N; i++)
	{	
		cin>>A[i];	
	}

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

	long long ans = 0;

	int l,r;
	l=0,r=N-1;

	ans += A[r] - A[l];

	long long a1,a2;
	int s1,s2;
	a1 = A[l];s1=0;
	a2 = A[r];s2=1;

	while (l+1 < r)
	{

		long long b1, b2;
		if (s1)
		{
			b1 = a1 - A[l+1];
		}
		else
		{
			b1 = A[r-1] - a1;
		}
		
		if (s2)
		{
			b2 = a2 - A[l + 1];
		}
		else
		{
			b2 = A[r - 1] - a2;
		}

		if (b1 > b2)
		{
			ans += b1;
			if (s1)
			{
				l++;
				a1 = A[l];
			}
			else {
				r--;
				a1 = A[r];
			}
			s1^=1;
		}
		else
		{
			ans += b2;
			if (s2)
			{
				l++;
				a2 = A[l];
			}
			else {
				r--;
				a2 = A[r];
			}
			s2^=1;
		}
	}

	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
ll n;
int main()
{
    cin>>n;
    ll ans=n-1;
    for(ll m=(ll)sqrt(n+.5);m;m--)
        if(n%m==0)
            ans=min(ans,m+n/m-2);
    printf("%lld\n",ans);
    return 0;
}


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

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

const int INF = 1e9;
const int MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, M; cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n+1);
  rep(i, n) cin >> a[i+1];
  vector<bool> visit(n+1, false);
  map<int, int> mp;
  mp[1] = 0;
  visit[1] = true;

  int now = 1;
  vector<int> city(n);
  city[0] = 1;
  rep(i, n) {
    now = a[now];
    if(visit[now]) {
      if(k-mp[now] < 0) {
        cout << city[k] << endl;
        return 0;
      }
      k -= mp[now];
      k %= i+1-mp[now];

      cout << city[mp[now]+k] << endl;
      return 0;
    }
    visit[now] = true;
    mp[now] = i+1;
    city[i+1] = now;
  }
}

Measured memory_bytes: 14716
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i,N) cin >> H[i];
    sort(ALL(H));
    reverse(ALL(H));
    ll ans = 0;
    rep(i,N){
        if(i >= K){
            ans += H[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
(setq a(read))(setq b(read))(setq k(read))
(setq l'())
(loop for i from a to (+ a(1- k))do(setq l(cons i l)))
(loop for i from (- b(1- k)) to b do(setq l(cons i l)))
(dolist(i(remove-if (lambda(x)(or(> a x)(< b x)))(remove-duplicates(sort l #'<))))(format t"~A~%"i))


Measured memory_bytes: 6632
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  string s; cin >> s;
  cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;

}

// EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define N ((ll)101*1000)
#define INF ((ll)2e9)

ll n,t,maxi,sum;

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>t;
	for(int i=0;i<t;i++)
	{
		ll x;
		cin>>x;
		maxi=max(maxi,x);
		sum+=x;
	}
	sum-=maxi;
	if(sum>=maxi-1)cout<<"0\n";
	else cout<<maxi-sum-1<<"\n";
	
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"
)

const (
	limitSecs = 2.0
)

// D
var (
	D         int
	c         [26]int
	s         [][26]int
	startTime time.Time
)

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

func calcScore(t []int) int {
	var last [26]int
	score := 0
	S := 0
	for i := 0; i < 26; i++ {
		last[i] = -1
	}
	for d := 0; d < len(t); d++ {
		S += s[d][t[d]]
		last[t[d]] = d
		for i := 0; i < 26; i++ {
			S -= c[i] * (d - last[i])
		}
		score += max(1000000+S, 0)
	}
	return score
}

func solution3() []int {
	var t []int
	for d := 0; d < D; d++ {
		score := -1
		best := -1
		t = append(t, 0)
		for i := 0; i < 26; i++ {
			t[len(t)-1] = i
			newScore := calcScore(t)
			if newScore > score {
				best = i
				score = newScore
			}
		}
		t[len(t)-1] = best
	}
	return t
}

func optimize1(t []int) []int {
	score := calcScore(t)
	for time.Now().Sub(startTime).Seconds()+0.02 < limitSecs {
		d := rand.Intn(D)
		q := rand.Intn(26)
		old := t[d]
		t[d] = q
		newScore := calcScore(t)
		if newScore < score {
			t[d] = old
		} else {
			score = newScore
		}
	}
	return t
}

func main() {
	defer flush()

	startTime = time.Now()

	D = readInt()
	for i := 0; i < 26; i++ {
		c[i] = readInt()
	}
	s = make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			s[i][j] = readInt()
		}
	}

	t := solution3()
	t = optimize1(t)
	for d := 0; d < D; d++ {
		println(t[d] + 1)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 2184
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    edge_matrix = [[False]*N for _ in range(N)]
    for _ in range(M):
        a,b = MI_()
        edge_matrix[a][b] = True
        edge_matrix[b][a] = True
    ans = 0
    for it in permutations([i for i in range(N)]):
        path = [i for i in it]
        if path[0]!=0:
            continue
        ok = True
        for i in range(N-1):
            from_ = path[i]
            to_ = path[i+1]
            if not edge_matrix[from_][to_]:
                ok = False
                break
        if ok:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;
int A[MAX_N];

signed main()
{
  int ans = 0;
  cin >> N;
  REP(n,N) {
    cin >> A[n];
    if(A[n]%2 == 1) {
      ans++;
    }
  }

  if(ans >= 1) {
    cout << "first" << endl;
  } else {
    cout << "second" << endl;
  }

  return 0;
}

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

int main()
{
	int n, k, x, q;
	cin>>n>>k>>q;
	int a[n]={0};

	for(int i=0;i<q;i++){
		cin>>x;
		a[x-1]++;
	}
	for(int i=0;i<n;i++){
		if(a[i]>q-k)cout<<"Yes" << endl;
		else cout << "No" << endl;
	}
}

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
a_ = 0
b_ = 0
count = 0

for i in range(n):
  a = As[i]
  b = Bs[i]
  
  if a >= b_:
    count += b_
    a = a - b_
  else:
    count += a
    a = 0
  
  if a >= b:
    count += b
    b_ = 0
  else:
    count += a
    b_ = b - a

count += min(As[-1], b_)
print(count)

Measured memory_bytes: 18624
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

primeFactors :: Int -> IM.IntMap Int
primeFactors n = if IM.null ans then IM.fromList [(n, 1)] else ans where
    ans = fst $ foldl go (IM.empty, n) $ takeWhile ((<= n) . (^2)) [2..]
    divCount divisor num acc = case num `divMod` divisor of
        (result, 0) -> divCount divisor result $ acc + 1
        (_, _) -> (acc, num)
    go (maps, num) divisor = case divCount divisor num 0 of
        (0, _) -> (maps, num)
        (m, num') ->  (IM.insert divisor m maps, num')

dropR :: Int -> [a] -> [a]
dropR n xs = reverse $ drop n $ reverse xs

main :: IO ()
main = do
  [a, b] <- words <$> getLine
  let a' = read a :: Int
  let b' = (read (filter (/= '.') b) :: Int)
  putStrLn $ case dropR 2 $ show $ a' * b' of
    "" -> "0"
    n -> n




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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string N;
	bool ans = false;

	cin >> N;

	rep(i, 3) if (N[i] == '7') ans = true;
	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if ( a+b > c+d ) {
    cout << "Left" << endl;
  } else if ( a+b < c+d ) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3624
#include <stdio.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define FOR(i,a,n) for(int i=a;i<n;i++)
int main(void)
{
	int k,t,a,max=0;
	scanf("%d %d",&k,&t);
	FOR(i,0,t){
		scanf("%d",&a);
		max=MAX(max,a);
	}
	printf("%d",MAX(max-1-(k-max),0));
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
 
using namespace std;
 
typedef pair<int,int> ii;
 
bool LT(double a,double b) { return !equals(a,b) && a < b ; }
 
struct Edge {
  int to,cap;
  double cost;
  int rev;
};
 
const int MAX_V = 1000, IINF = INT_MAX;
int V;
vector<Edge> G[MAX_V];
 
double h[MAX_V],dist[MAX_V];//////// fpwjefoajfpojeawfopefa
int prevv[MAX_V], preve[MAX_V];
 
 
inline void add_edge(int from,int to,int cap,double cost){
  G[from].push_back((Edge){to,cap,cost,G[to].size()});
  G[to].push_back((Edge){from,0,-cost,G[from].size()-1});
}
 
double min_cost_flow(int s,int t,int f){
  double res = 0;
  fill(h,h+V,0);
  while(LT(0,f)){
    priority_queue<ii,vector<ii>,greater<ii> > Q;
    fill(dist,dist+V,INT_MAX);
    dist[s] = 0;
    Q.push(ii(0,s));
    while( !Q.empty() ){
      ii p = Q.top(); Q.pop();
      int v = p.second;
      if( LT(dist[v],p.first) ) continue;
      for(int i=0;i<G[v].size();i++)      {
    Edge &e = G[v][i];
    if( LT(0,e.cap) && LT(dist[v]+e.cost+h[v]-h[e.to],dist[e.to]) ) {
      dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
      prevv[e.to] = v;
      preve[e.to] = i;
      Q.push(ii(dist[e.to],e.to));
    }
      }
    }
    if( equals(dist[t],INT_MAX) ) return -1;
    rep(v,V) h[v] += dist[v];
    int d = f;
    for(int v=t;v!=s;v=prevv[v]) d = min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d * h[t];
    for(int v=t;v!=s;v=prevv[v]) {
      Edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
 
typedef vector<double> vd;
typedef vector<vd> mat;
 
 
 
vector<double> f(const mat& A,const vd& b){
  int n = A.size();
  mat B(n,vd(n+1));
  rep(i,n) rep(j,n) B[i][j] = A[i][j];
  rep(i,n) B[i][n] = b[i];
 
  rep(i,n){
    int pivot = i;
    REP(j,i,n) if( LT(abs(B[pivot][i]),abs(B[j][i])) ) pivot = j;
    swap(B[i],B[pivot]);
    if( abs(B[i][i]) < EPS ) return vd();
    REP(j,i+1,n+1) B[i][j] /= B[i][i];
    rep(j,n){
      if( i != j ){
    REP(k,i+1,n+1) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }  
 
  vd x(n);
  rep(i,n) x[i] = B[i][n];
  return x;
}
 
void init(int size=MAX_V){
  rep(i,size) G[i].clear();
}
 
int main(){
  int T;
  cin >> T;
  while( T-- ){
    int N,s,t,F;
    cin >> N >> s >> t >> F;
    mat A(N,vector<double>(N,0));
    vector<double> b(N,0);
    rep(i,N) {
      rep(j,N) {
    cin >> A[i][j];
      }
      cin >> b[i];
    }
     
    vector<double> ans = f(A,b);
     
    init();
 
    rep(i,N) {
      int M;
      cin >> M;
      vector<ii> vec(M);
      rep(j,M) cin >> vec[j].first;
      rep(j,M) cin >> vec[j].second;
      rep(j,M) {
    add_edge(i,vec[j].first,vec[j].second,abs(ans[i]-ans[vec[j].first]));
      }
    }
 
    V = N;
    double temp = min_cost_flow(s,t,F);
    if( equals(temp,-1) ) puts("impossible");
    else printf("%.10f\n",temp);
 
  }
  return 0;
}

Measured memory_bytes: 2076
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        v.push_back(s);
    }

    sort(v.begin(),v.end());
    vector<ll>res;
    ll cnt=0;
    for(int i=0;i<n-1;i++){
        cnt+=1;
        if(v[i]==v[i+1])continue;
        else{ res.push_back(cnt);cnt=0;}
    }
    res.push_back(cnt+1);
    ll ans=0;
    for(int i=0;i<res.size();i++){
        ans+=ll((((res[i]-1)*res[i])/2));
    }
    cout<<ans<<endl;
    return 0;
    }


Measured memory_bytes: 7284
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>

int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; }
int max(int a, int b) { return a >= b ? a : b; }
int min(int a, int b) { return a <= b ? a : b; }
int dsum(int x) { int r=0; while(x){ r+=(x%10); x/=10; } return r;}
void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; return; }

int main(void) {
  int w;
  scanf("%d",&w);
  printf("%d\n",w*32);
  return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

const int N = 16;
const int W = 4;
const int INF = 1000000007;
const int BITMAX = (1<<(W*W));

int n;
int sh[N];
int sw[N];

vector<string> color;


void input(){
	cin>>n;
	rep(i,n)cin>>sh[i]>>sw[i];
	
	rep(i,W){
		string str;
		cin>>str;
		color.pb(str);
	}
}

bool hasbit(int state, int i){
	return (state&(1<<i))>0;
}

bool printbit(int state){
	rep(i,W*W)printf("%d",(state&(1<<i))>0 ? 1:0);
}

class Board{
	public:
	int state;
	Board(int state):state(state){}
	
	char getMasuChar(int x,int y){
		int num = y*W + x;
		if((state&(1<<num))>0)return '?';
		return color[y][x];
	}
	
	bool canput(int index,int x,int y){
		int r=0,g=0,b=0;
		rep(i,sh[index]){
			rep(j,sw[index]){
				int nx = x+j;
				int ny = y+i;
				
				if(nx<0 || ny<0 || nx>=W || ny>=W)continue;
				
				char c = getMasuChar(nx, ny);
				if(c=='R')r++;
				if(c=='G')g++;
				if(c=='B')b++;
			}
		}
		if(r>0 && g==0 && b==0)return true;
		if(r==0 && g>0 && b==0)return true;
		if(r==0 && g==0 && b>0)return true;
		return false;
	}
	
	void put(int index,int x,int y){
		rep(i,sh[index]){
			rep(j,sw[index]){
				int nx = x+j;
				int ny = y+i;
				
				if(nx<0 || ny<0 || nx>=W || ny>=W)continue;
				
				int num = ny*W + nx;
				state |= (1<<num);
			}
		}
	}
	
	int getState(){
		return state;
	}
	
	void print(){
		printf("----------------------------\n");
		rep(i,W){
			rep(j,W){
				printf("%c ",getMasuChar(i,j));
			}puts("");
		}
	}
};

int memo[BITMAX];

int saiki(int state){
	if(state == (1<<(W*W))-1)return 0;
	if(memo[state]!=-1)return memo[state];
	
	Board b = Board(state);
	int ret = INF;
	
	rep(i,n){
		reps(y, 1-sh[i], W){
			reps(x, 1-sw[i], W){
				if(b.canput(i, x, y)){
					Board copy = b;
					copy.put(i, x, y);
					
					ret = min(ret, saiki(copy.getState())+1);
				}
			}
		}
	}
	
	return memo[state] = ret;
}

void solve(){
	rep(i,BITMAX)memo[i]=-1;
	
	int ans = saiki(0);
	cout<<ans<<endl;
}


int main(){
	input();
	solve();
}

Measured memory_bytes: 1468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int n;

int main()
{
    while (cin >> n)
    {
        if (n == 0)
            return 0;
        vector<ll> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        ll ans = inf;
        for (int i = 0; i + 1 < n; i++)
        {
            ans = min(ans, a[i + 1] - a[i]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main(){
    int A,B,c;
    cin >> A >> B;
    c=0;
    if(A>8||B>8)
        c=1;
    if(c==1)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N, cur;
  	map <int, int> sarvesh;
  	cin >> N;
  	int arr[N+1];
  	
  	for(int i=1; i<=N; i++) {
		cin >> cur;
      	sarvesh[cur] = i;
    }
    for(int i=1; i<=N; i++)
      cout << sarvesh[i] << " ";
}

Measured memory_bytes: 5504
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B, C;
    std::cin >> A >> B >> C;

    bool flag = false;
    for (int i = 0; i < 10000000; i++) {
        if (A*i % B == C) {
            flag = true;
            break;
        } 
    }

    if (flag) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO"  << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = [0] * (N+1)
for a, b in zip(A, B):
    count[a] += 1
    count[b] += 1

for i in range(N+1):
    if count[i] > N:
        print('No')
        quit()

diff = 0
checked = set()
ida = 0
for i, b in enumerate(B):
    if b in checked:
        continue
    checked.add(b)
    while ida < N and A[ida] <= b:
        ida += 1
    diff = max(diff, ida - i)


print('Yes')
print(*(B[-diff:]+B[:-diff]))

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

#define ll long long

int main(void)
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a<b && b<c)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}




Measured memory_bytes: 2096
import java.util.*;
import static java.lang.System.*;

public class Main{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if(A<=9){
        if(B<=9){
        out.println(A*B);
        }else
        out.println("-1");
        }else
        out.println("-1");
}
}


Measured memory_bytes: 21844