akhauriyash/Code-Regression huggingface dataset:
import collections
class Dinic:
    refs = {}
    def __init__(self, n):
        self.n = n
        self.g = [[] for i in xrange(n)]
    def add_edge(self, fr, to, cap):
        self.g[fr].append([to, cap, len(self.g[to])])
        self.g[to].append([fr, 0, len(self.g[fr])-1])
    def add_multi_edge(self, v1, v2, cap1, cap2):
        ref = [v2, cap1, len(self.g[v2])]
        self.g[v1].append(ref)
        self.g[v2].append([v1, cap2, len(self.g[v1])-1])
        self.refs[v1, v2] = ref
    def bfs(self, s):
        level = [-1]*self.n
        deq = collections.deque()
        level[s] = 0
        deq.append(s)
        while deq:
            v = deq.popleft()
            for e in self.g[v]:
                if e[1]>0 and level[e[0]]<0:
                    level[e[0]] = level[v] + 1
                    deq.append(e[0])
        self.level = level
    def dfs(self, v, t, f):
        if v==t: return f
        es = self.g[v]
        level = self.level
        for i in xrange(self.it[v], len(self.g[v])):
            e = es[i]
            if e[1]>0 and level[v]<level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d>0:
                    e[1] -= d
                    self.g[e[0]][e[2]][1] += d
                    self.it[v] = i
                    return d
        self.it[v] = len(self.g[v])
        return 0
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0: break
            self.it = [0]*self.n
            while True:
                f = self.dfs(s, t, 10**9+7)
                if f>0:
                    flow += f
                else:
                    break
        return flow
n, m = map(int, raw_input().split())
dinic = Dinic(n)
es = []
for i in xrange(m):
    x, y = map(int, raw_input().split())
    dinic.add_multi_edge(x-1, y-1, 1, 1)
    es.append((x-1, y-1))
s, t = map(int, raw_input().split())
f = dinic.max_flow(s-1, t-1)
print f
ans = []
for i, e in enumerate(es):
    if dinic.refs[e][1]>1:
        ans.append(i+1)
print len(ans)
if ans:
    print "\n".join(map(str, ans))

Measured memory_bytes: 7144
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 = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int[] L = new int[N];
    for(int i = 0; i < N; i++ ){
      L[i] = sc.nextInt();
    }
    Main abc119C = new Main();
    System.out.println(abc119C.solve(A, B, C, L));
  }

  public int solve(int A, int B, int C, int[] L) {
    ABC119CSolve abc119CSolve = new ABC119CSolve(A, B, C, L);
    return abc119CSolve.solve();
  }

  class ABC119CSolve{
    int A;
    int B;
    int C;
    int[] L;
    int INF = (int) Math.pow(10, 9);
    public ABC119CSolve(int A, int B, int C, int[] L) {
      this.A = A;
      this.B = B;
      this.C = C;
      this.L = L;
    }

    public int solve(){
      return this.dfs(0, 0, 0, 0);
    }

    private int dfs(int index, int a, int b, int c) {
      if(index == L.length) {
        if(a > 0 && b > 0 && c > 0) {
          return Math.abs(this.A - a) + Math.abs(this.B - b) + Math.abs(this.C - c) - 30;
        } else {
          return INF;
        }
      }
      int ret0 = dfs(index+1, a, b, c);
      int ret1 = dfs(index+1, a+L[index], b, c) + 10;
      int ret2 = dfs(index+1, a, b+L[index], c) + 10;
      int ret3 = dfs(index+1, a, b, c+L[index]) + 10;
      return Math.min(Math.min(Math.min(ret0, ret1), ret2), ret3);
    }
  }
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#define debug(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#define debug(...) __VA_ARGS__
#endif
const int N = 100005;

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    ll x,y,z;
    cin >> x >> y >> z;

    if (x + y + z >= 22)
        cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
%>

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,S[100000]={-1},q,T,cnt=0;
	scanf("%d",&n);

	for(int i=0;i<n;i++)
		scanf("%d",&S[i]);

	scanf("%d",&q);

	for(int i=0;i<q;i++){
		scanf("%d",&T);
		int left=0,right=n-1;

		while(left<=right){
			int mid=(left+right)/2;

			if(T==S[mid]){
				right=-1;
				break;
			}

			else if(T>S[mid])
				left=mid+1;

			else
				right=mid-1;
		}
		if(right==-1)
			cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

long long read(){
	long long i;
	cin >> i;
	return i;
}

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

	const int turns = read();
	int t_win = 0;
	int h_win = 0;
	REP(i, turns) {
		string t_card, h_card;
		cin >> t_card >> h_card;
		int result = t_card.compare(h_card);
		if (result > 0){
			t_win += 3;
		} else if (result < 0) {
			h_win += 3;
		} else {
			t_win++;
			h_win++;
		}
	}
	cout << t_win << " " << h_win << endl;

	return 0;
}



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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

template <class T>
void warshall_floyd(vector<vector<T>>& mat, const T inf) {
    const auto len           = mat.size();
    rep(i, 0, len) mat[i][i] = 0;
    rep(k, 0, len) rep(i, 0, len) rep(j, 0, len) {
        if (mat[i][k] == inf || mat[k][j] == inf) continue;
        chmin(mat[i][j], mat[i][k] + mat[k][j]);
    }
}
//---------------------------------------------------------------------------------------------------

signed main() {
    int V, E;
    cin >> V >> E;
    const auto inf = numeric_limits<i64>::max();
    vector<vector<i64>> mat(V, vector<i64>(V, inf));
    rep(i, 0, E) {
        int u, v, w;
        cin >> u >> v >> w;
        mat[u][v] = w;
    }

    warshall_floyd(mat, inf);
    rep(i, 0, V) {
        if (mat[i][i] < 0) {
            cout << "NEGATIVE CYCLE\n";
            return 0;
        }
    }

    rep(i, 0, V) rep(j, 0, V) {
        auto w = mat[i][j];
        if (w == inf)
            cout << "INF";
        else
            cout << w;
        cout << (j == V - 1 ? "\n" : " ");
    }
}



Measured memory_bytes: 3308
#include <stdio.h>
#include <stdlib.h>

unsigned int calculate_num_monitor (const unsigned int* const num_tree_all, const unsigned int* const num_range)
{
	return (*num_tree_all + *num_range * 2U) / (*num_range * 2U + 1U);
}

int main (void)
{
	// variables for main process
	unsigned int N;
	unsigned int D;
	int          rtvl_scanf;

	// STEP.01
	// read out the given data
	rtvl_scanf = scanf("%d %d", &N, &D);

	// STEP.02
	// output the answer of this task
	printf("%d\n", calculate_num_monitor(&N, &D));

	// STEP.END
	return EXIT_SUCCESS;
}

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

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

#define mod 1000000007
#define N 100005
ll m, n, a, now[N];

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
    cin >> n >> m;
    memset(now, 0, sizeof(now));
    for (ll i=0; i<m; i++) {
        cin >> a;
        now[a]=-1;
    }
    now[0]=1;
    if (now[1]!=-1) now[1]=1;
    for (ll i=2; i<=n; i++) {
        if (now[i]==-1) continue;
        ll x = max(ll(0), now[i-1]);
        ll y = max(ll(0), now[i-2]);
        now[i] = (x+y)%mod;
    }
    cout << now[n] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
//const ll INF = 1e18;
//const ld PI = acos(-1L);

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

    int X, N;
    in(X); in(N);
    // 0 to 101
    vector<int> p(101, 0);
    rep(i, N) {
        int tmp;
        in(tmp);
        p[tmp] = 1;
    }
    int ans;
    for(int i=X; i>=0; i--) {
        if (p[i] == 0) {
            ans = i;
            break;
        }
    }
    for(int i=X+1; i<=101; i++) {
        if (p[i] == 0 && X - ans > i - X) {
            ans = i;
            break;
        }
    }
    out(ans);


        return 0;
    }


Measured memory_bytes: 3656
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        int K = sc.nextInt();

        Queue<Long> q = new PriorityQueue<>();

        for(long i = 1; i < 10; i++)
            q.offer(i);

        int count = 0;

        while(count++ < K-1) {
            long num = q.poll();

            if(num % 10 != 0) {
                q.offer(num*10 + num%10-1);
            }

            q.offer(num*10 + num%10);

            if(num % 10 != 9){
                q.offer(num*10 + num%10+1);
            }
        }

        os.println(q.poll());
    }
}

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

using namespace std;

const int N = 110;

int q[N];
int a[N];

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

    int len = n;
    int cnt = 1;
    for (int i = 1; i <= n ; i ++ )
    {
        cin >> q[i];
    }

    while(len)
    {
        int t = len;
        for (int i = len; i >= 1; i -- )
        {
            if(q[i] == i)
            {
                a[cnt++] = i;

                for (int j = i; j <= len; j ++ )
                {
                    q[j] = q[j+1];
                }


                len -- ;
                //cout << "q[i] = " << i << endl;
                break;
            }
        }
        //cout << "cnt1 = " << cnt1++;
        if(len == t) break;
    }

    //cout << "cnt = " << cnt << endl;

    if(len > 0) cout << "-1" << endl;
    else
    {
        for (int i = cnt-1; i >= 1; i -- )
        {
            cout << a[i] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	long long int n, sum = 0;
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) {
		if ( i % 3 == 0 && i % 5 == 0) {
			continue;
		}
		else if (i % 3 == 0) {
			continue;
		}
		else if (i % 5 == 0) {
			continue;
		}
		else {
			sum += i;
		}
	}
	
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1736
n,m=map(int,input().split())
stak=[[],[],[],[],[],[],[],[]]
for i in range(n):
    a=list(map(int,input().split()))
    stak[0].append(a[0]+a[1]+a[2])
    stak[1].append(a[0]+a[1]-a[2])
    stak[2].append(a[0]-a[1]+a[2])
    stak[3].append(a[0]-a[1]-a[2])
    stak[4].append(-a[0]+a[1]+a[2])
    stak[5].append(-a[0]+a[1]-a[2])
    stak[6].append(-a[0]-a[1]+a[2])
    stak[7].append(-a[0]-a[1]-a[2])
for i in range(8):
    stak[i].sort(reverse=True)
answer=0
for i in range(8):
    t=0
    for j in range(m):
       t+=stak[i][j] 
    if answer <= t:
        answer = t
print(answer)

Measured memory_bytes: 3432
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if i * 500 + j * 100 + k * 50 == X:
                ans += 1
print(ans)

Measured memory_bytes: 82620
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

H,W = map(int,input().split())

def check(H,W):
	ans = INF
	for i in range(1,H):
		S1 = W * i
		left = W//2
		right = W - left
		S2 = left * (H-i)
		S3 = right * (H-i)
		ans = min(max(S1,S2,S3)-min(S1,S2,S3),ans)
	return ans

if H%3 == 0 or W%3 == 0:
	print(0)
else:
	ans1 = check(H,W)
	ans2 = check(W,H)
	print(min(ans1,ans2,H,W))

Measured memory_bytes: 3888
h,w,k = map(int,input().split())

s = [input() for _ in range(h)]

t = [[0 for _ in range(w)] for _ in range(h)]

i = 1

for y in range(h):
    for x in range(w):
        if(s[y][x] == '#'):
            t[y][x] = i
            i += 1

for y in range(h):
    l = 0
    for x in range(w):
        if(t[y][x] != 0):l = t[y][x]
        else:t[y][x] = l
    l = 0
    for x in range(w)[::-1]:
        if(t[y][x] != 0):l = t[y][x]
        else:t[y][x] = l

for y in range(h):
    if(t[y][0] == 0):
        for y2 in range(y,h):
            if(t[y2][0] == 0):continue
            for x in range(w):
                t[y][x] = t[y2][x]
            break
                
for y in range(h)[::-1]:
    if(t[y][0] == 0):
        for y2 in range(0,y)[::-1]:
            if(t[y2][0] == 0):continue
            for x in range(w):
                t[y][x] = t[y2][x]
            break


for x in t:print(*x)


Measured memory_bytes: 7568
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <list>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n) {
	return 0;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1-x2),2) + pow(abs(y1-y2),2));
}


//場合の数を求める
int calcNumOfCombination(int n, int r) {
	int num = 1;
	for (int i = 1; i <= r; i++) {
		num = num * (n - i + 1) / i;
	}
	return num;
}
int main()
{
	int n;
	cin >> n;
	string temp;
	map<string,int> s;
	for (int i = 0;i < n;i++) {
		cin >> temp;
		sort(temp.begin(), temp.end());
		s[temp]++;
	}

	//cout << "----------------------" << endl;
	ll ans = 0;
	ll ans_temp;
	auto itr = s.begin();
	for (itr = s.begin(); itr != s.end(); itr++) {
		//cout << itr->first << endl;
		if(itr->second != 1){
			ans_temp = itr->second;
			ans += (ans_temp * (ans_temp -1)/2);
		}
	}

	cout << ans << endl;

	

	system("pause");
	return 0;
}

Measured memory_bytes: 8312
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;

int main()
{
    ll s;
    cin>>s;
    ll dp[s+1]={0};
    dp[0]=1LL;dp[1]=0;dp[2]=0;
    for(int i=3;i<=s;i++)
    {
        for(int j=3;j<=i;j++)
        {
            dp[i]+=dp[i-j];
            dp[i]%=MOD;
        }
    }
    cout<<dp[s]<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

int k,n;
int l[111];

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

  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> l[i];
  }

  sort(l, l+n);

  int ans = 0;
  for(int i=0;i<k;i++){
    ans += l[n-1-i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char S[200];

    scanf("%s", S);

    int i;

    while(S[i] != '\0'){
        if((i + 1) % 2 == 0){
            if(S[i] == 'R'){
                break;
            }
        }
        else{
            if(S[i] == 'L'){
                break;
            }
        }
        i ++;
    }
    if(S[i] == '\0'){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void) {
  int i, k;
  char str[101];

  scanf("%d", &k);
  scanf("%s", str);

  i = strlen(str);
  if (i <= k){
    printf("%s", str);
  }else{
    char str2[k+1];
    strncpy(str2, str, k);
    if (k > 0) {
      str2[k] = '\0';
    }else{}
    strcat(str2, "...");
    puts(str2);
  }

  return 0;
}


Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int[] a = new int[7];
        for (int i = 1; i < 7; i++) {
            a[i] = sc.nextInt();
        }
        char[] b = sc.next().toCharArray();
        for (int i = 0; i < b.length; i++) {
            if (b[i] == 'N') {
                a[0] = a[1];
                a[1] = a[2];
                a[2] = a[6];
                a[6] = a[5];
                a[5] = a[0];
            } else if (b[i] == 'S') {
                a[0] = a[1];
                a[1] = a[5];
                a[5] = a[6];
                a[6] = a[2];
                a[2] = a[0];
            } else if (b[i] == 'E') {
                a[0] = a[1];
                a[1] = a[4];
                a[4] = a[6];
                a[6] = a[3];
                a[3] = a[0];
            } else {
                a[0] = a[1];
                a[1] = a[3];
                a[3] = a[6];
                a[6] = a[4];
                a[4] = a[0];
            }
        }
        System.out.println(a[1]);
    }
}


Measured memory_bytes: 26228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    vector<ll> B(1111111);
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
        B[A[i]]++;
    }
    sort(ALL(A));
    int count = 0;
    REP(i,N){
        if(B[A[i]] > 0){
            for(int l = 2;l*A[i] < 1000001;l++){
                B[l*A[i]] = 0;
            }
            if(B[A[i]] > 1)B[A[i]] = 0;
        }
    }
    REP(i,1000005)count += B[i];
    cout << count << "\n";
}

Measured memory_bytes: 13496
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;

using namespace std;
using ll = long long;

/*
int main() {
    ll H, W;
    cin >> H >> W;
    if(H>W) swap(H, W);
    if(H==1)
        cout << 1 << endl;

    else
        cout << (H*W +1)/2 << endl;

        return 0;
}
*/

int main(){

 long long H,W;
 cin>>H>>W;

 if(H>W) swap(H,W);

 if(H == 1)
    cout<<"1"<<endl;
 else
    cout<<(H*W+1)/2<<endl;


return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)


int main(){
    int n,m,a,h,p,q,i;
    vector<pair<int, pair<int,int> > > vp;

    while( cin >> n >> m >> a, n|m|a ){
        vp.clear();
        rep(i,m){
            cin >> h >> p >> q;
            vp.push_back(make_pair(h,make_pair(p,q)));
        }
        sort(rall(vp));
        rep(i,m){
            int e = vp[i].second.second;
            int d = vp[i].second.first;
            if( e == a || d == a ){
                a = (e + d) - a;
            }
        }
        cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 932
s = input()
t = input()

s_len = len(s)
t_len = len(t)

dp = [[0 for _ in range(t_len+1)] for _ in range(s_len+1)]

for i in range(1, s_len+1):
    for j in range(1, t_len+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]+1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = ''
x = s_len
y = t_len

while x > 0 and y > 0 :
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        x -= 1
        y -= 1
        ans = ans + s[x]

ans = ans[::-1]
print(ans)






Measured memory_bytes: 119772
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin>> a >> b;
    if(a >= 13)
    {
        cout << b << endl;
    }
    else if(a >= 6 && a <= 12)
    {
        cout << b/2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
    return 0;
}

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

using namespace std;

int main() {
  long long i, o, j, l, _;
  cin >> i >> o >> _ >> j >> l >> _ >> _;
  
  long long res = o + i/2*2 + j/2*2 + l/2*2;
  if (i && j && l)
    res = max(res, o + (i-1)/2*2 + (j-1)/2*2 + (l-1)/2*2 + 3);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<int> P(N);
	vector<int> ind(N);
	for(int i=0;i<N;i++){
		cin>>P[i];
		P[i]--;
		ind[P[i]] = i;
	}
	
	vector<int> K(N,0);
	
	for(int i=0;i<N;i++){
		if(i!=0&&ind[i] > ind[i-1]){
			K[i] = K[i-1] + 1;
		}
		else{
			K[i] = 1;
		}
	}
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		ans = max(ans,K[i]);
	}
	
	cout<<N-ans<<endl;
	
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define N 305
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N][N],sum=1e18,t,tut[N],cnt[N],mark[N];

int main()
{
	fast;
	cin>>n>>m;
	fo(i,1,n)
	tut[i]=1;
	fo(i,1,n)
		fo(j,1,m)
			cin>>ar[i][j];
	ll x=m-1;
	while(x--)
	{
		ll mk=0;
		ll mki=0;
		fo(i,1,m)
			cnt[i]=0;
		fo(i,1,n)
		{
			ll x=ar[i][tut[i]];
			cnt[x]++;
			if(cnt[x]>mk)
			{
				mk=cnt[x];
				mki=x;
			}
		}
		// cout<<mk<<sp<<mki<<endl;
		mark[mki]=1;
		fo(i,1,n)
		{
			while(mark[ar[i][tut[i]]])
				tut[i]++;
		}
		sum=min(sum,mk);
	}
	if(m==1)
		sum=n;
	cout<<sum<<endl;


}



Measured memory_bytes: 4348
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Max zhi5968
typedef long long ll;
using namespace std;
 
int main ()
{
	string s1,s2;
	cin>>s1>>s2;
	if(s1[0]==s2[2]&&s1[2]==s2[0]&&s1[1]==s2[1])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

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

using namespace std ;

map < long long , long long > mp1 ;

int a ;

long long x , cnt = 1 ;

int main ()
{
    cin >> a ;
    for ( int i = 2 ; i <= a ; ++ i ){
        x = i ;
        for ( int j = 2 ; j <= x ; ++ j ){
            while ( x % j == 0 ){
                mp1 [ j ] ++ ;
                x /= j ;
            }
        }
    }
    int d = 1e9 + 7 ;
    for ( int i = 1 ; i <= a ; ++ i ){
        cnt = ( cnt * ( mp1 [ i ] + 1 ) ) % d ;
    }
    cout << cnt ;
}


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

int main(){
    int N;
    cin >> N;
    int num = 0;
    bool flag = false;
    int numberFlag = 1;

    for(int i = 0; i < N; i++){
        cin >> num;
        if(num % 2 == 0){
            if(num % 3 == 0 || num % 5 == 0){
                flag = true;
            }else{
                flag = false;
                numberFlag = -1;
            }
        }else{

        }
    }


    if(numberFlag > 0){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, D[1 << 19], S[1 << 19];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) scanf("%d", &D[i]);

	bool flag = true;

	// ステップ 1 : 左から行けるか
	for (int i = 1; i <= N; i++) {
		int sz = D[i] / 10;
		int cl = i, cr = i + sz; cl = max(cl, 1); cr = min(cr, N);
		S[cl + 1]++; S[cr + 1]--;
	}
	for (int i = 1; i <= N + 1; i++) S[i] += S[i - 1];
	for (int i = 2; i <= N; i++) { if (S[i] == 0) flag = false; }
	for (int i = 0; i <= N + 1; i++) S[i] = 0;

	// ステップ 2 : 右から行けるか
	for (int i = 1; i <= N; i++) {
		int sz = D[i] / 10;
		int cl = i - sz, cr = i; cl = max(cl, 1); cr = min(cr, N);
		S[cl + 1]++; S[cr + 1]--;
	}
	for (int i = 1; i <= N + 1; i++) S[i] += S[i - 1];
	for (int i = 2; i <= N; i++) { if (S[i] == 0) flag = false; }
	for (int i = 0; i <= N + 1; i++) S[i] = 0;

	if (flag == true) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}


Measured memory_bytes: 5504
using System;
using System.Collections.Generic;

class Program
{
    public void Proc()
    {
        string[] inpt = Console.ReadLine().Split(' ');
        int a = int.Parse(inpt[0]);
        int b = int.Parse(inpt[1]);
        int c = int.Parse(inpt[2]);

        int ans = 0;
        for( int i=a; i<= b; i++)
        {
            if(c % i == 0)
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }



    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    ll n, k; cin>>n>>k;
    vector<ll> a(n), sum(n+1);
    sum[0]=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(i==0) sum[i+1]=a[i];
        else sum[i+1]=sum[i]+a[i];
    }

    vector<ll> b;
    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j++){
            b.emplace_back(sum[j]-sum[i-1]);
        }
    }
    sort(b.begin(), b.end(), greater<ll>());
    
    ll ans=0;
    for(int i=40; i>=0; i--){
        ll num=ans|(1LL<<i);

        int cnt=0;
        for(int j=0; j<b.size(); j++){
            if((num&b[j])==num) cnt++;
        }

        if(cnt>=k) ans|=(1LL<<i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
N = int(input())
S = input()

first = []

ans = 0
for i in range(N-2):
    if int(S[i]) in first:
        continue
    else:
        first.append(int(S[i]))
        second = []
        for j in range(i+1, N-1):
            if int(S[j]) in second:
                continue
            else:
                second.append(int(S[j]))
                ans += len(set(map(int, S[j+1:])))

print(ans)

Measured memory_bytes: 109276
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    int n = s.size() - 1;

    ll ans = 0;
    for(int bit = 0; bit < (1 << n); bit++) {
        int t = 0, k = 1;
        vector<string> A;
        rep(i, n) {
            if(bit >> i & 1) {
                A.push_back(s.substr(t, k));
                t += k;
                k = 1;
            } else k++;
        } 
        A.push_back(s.substr(t, k));
        rep(j, A.size()) {
            ans += stoll(A[j]);
        }
    }
    cout << ans << endl;
  
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] a= new int[n+1];
    int[] b= new int[n];
    for(int i=0;i<=n;i++){
      a[i]=sc.nextInt();
    }
    for(int i=0;i<n;i++){
      b[i]=sc.nextInt();
    }
    long df=0;
    for(int i=0;i<n;i++){
      if(a[i]<b[i]){
        b[i]=b[i]-a[i];
        df+=a[i];
//        a[i]=0;
        if(a[i+1]<b[i]){
//          b[i]=b[i]-a[i+1];
          df+=a[i+1];
          a[i+1]=0;
        }else{
          a[i+1]=a[i+1]-b[i];
          df+=b[i];
//          b[i]=0;
        }
      }else{
//        a[i]=a[i]-b[i];
        df+=b[i];
//        b[i]=0;
      }
    }
    System.out.println(df);
  }
}

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

int main(){
	long long N,A,mi,ans=0;
	cin >> N >> A; mi=A;
	for(int i=0; i<4; i++){
		cin >> A;
		mi=min(A,mi);
	}
	ans=N/mi;
	if(N%mi!=0) ans+=1;
	cout << ans+4 << endl;
}

Measured memory_bytes: 256
import math

a,b,h,m=map(int,input().split())

m_kaku=math.radians(6*m)
h_kaku=math.radians(30*h+m*0.5)

kaku=m_kaku-h_kaku


#kaku=min(kaku,180-kaku)


c2=a**2+b**2-2*a*b*math.cos(kaku)
c=c2**(0.5)

print(c)


Measured memory_bytes: 9560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, K;
    cin >> N >> K;
    if(K > (N-1) * (N-2) / 2){
        cout << -1 << endl;
        return 0;
    }

    VP ans;
    rep(i, 2, N+1){
        ans.push_back({1, i});
    }

    ll rem = (N - 1) * (N - 2) / 2 - K;
    ll cnt = 0;
    if(rem != 0){
        rep(i, 2, N){
            bool f = false;
            rep(j, i+1, N+1){
                ans.push_back({i, j});
                cnt++;
                if(cnt == rem){
                    f = true;
                    break;
                }
            }
            if(f) break;
        }
    }

    cout << ans.size() << endl;
    for(auto a : ans) cout << a.first << " " << a.second << endl; 
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    ll m, v, p, a[112345];

    cin >> n >> m >> v >> p;
    REP(i, n)
    cin >> a[i];

    sort(a, a + n);

    int l = -1;
    int r = n - p;

    while (r - l > 1)
    {
        int mid = (r + l) / 2;

        int vv = v - min(v, mid + 1 + p - 1);

        ll b = vv * m;

        bool ok = true;

        for (int i = mid + 1; i < n - (p - 1); i++)
        {
            if (a[i] > a[mid] + m)
            {
                ok = false;
                continue;
            }

            b -= min(m, (a[mid] + m) - a[i]);
        }

        if (b <= 0 && ok)
            r = mid;
        else
            l = mid;
    }

    cout << n - r << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

void solve() {
	int a, b, c; cin >> a >> b >> c;
	int ans = max(0, c-(a-b));
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


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

int main(){
    string N;
    cin >> N;
    int sum = 0;
    rep(i,N.size()){
        char num = N.at(i);
        sum += (int)num-48;
    }
    if(sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3728
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  if (a >= 1 && a < 10 && b >= 1 && b < 10) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 888
#include<bits//stdc++.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define MOD 1000000007
using namespace std;
typedef long long int ll;
int n,a,b,ans = 0;
vector<ll> sz, pw;vector<vector<int>> v;
void dfs(int node, int p) {// now , before
    sz[node] = 1;
    int pr = pw[1];
    for (int u : v[node]) {
        if (u != p) {
            dfs(u, node); sz[node] += sz[u];
            pr = (pr - pw[n - sz[u]] + MOD) % MOD;
        }
    }
    if (node != 1) {
        pr = (pr - pw[sz[node]] + MOD) % MOD;
    }
    pr = (pr + (v[node].size() - 1) * pw[n] % MOD + MOD) % MOD;
    ans = (ans + pr) % MOD;
}
int main() {
    cin >> n; v.resize(n+10), sz.resize(n+10), pw.resize(n+10);
    pw[0] = 1; pw[1] = (MOD + 1) / 2;
    rep(i, n - 1) {
        pw[i + 2] = (pw[i + 1] * pw[1]) % MOD;
        cin >> a >> b;
        v[a].push_back(b);v[b].push_back(a);
    }dfs(1, 0);
    cout << ans << endl;
}

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

int main(){
    string S;
    cin >> S;
    int n;
    n = S.length();
    string T;
    T = "";
    for ( int i = 0; i < n; ++i){
        T = T + "x";
    }
    cout << T << endl;
    return 0;
}


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

int main(void)
{
	int sum, type, total= 0;
	int cakes[10000]= {};

	cin>>sum>>type;
	for(int i= 0; i < type; i++)
		cin>>cakes[i];

	sort(cakes, cakes+type);
	total= cakes[type-1];
	for(int i= 0; i < type-1; i++)
		total-= cakes[i];
	total--;

	if(total < 0)
		total= 0;

	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
ll n,a,b,c;
ll ans;
int main(void){
    cin>>n;
    for(int i=1;i<n;i++){
        ans+=((n+i-1)/i-1);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3632
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

int main() {
  ll n;
  string str;
  cin >> n >> str;

  ll cnt = 0;
  ll ans = 0;
  for (char c : str) {
    if (c == '(') {
      cnt++;
    } else {
      if (cnt == 0)
        ans++;
      else
        cnt--;
    }
  }  // c

  string top = "";
  for (ll i = 0; i < ans; i++) {
    top += "(";
  }

  string bot = "";
  for (ll i = 0; i < cnt; i++) {
    bot += ")";
  }

  str = top + str + bot;

  cout << str << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i =1; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

int main() {
	int n,x,y;cin>>n>>x>>y;
  int d=0;
  vector<int> k(n,0);
  rep(i,n){
      int j=i+1;

    while(j<=n){
      if(i<x&&j<=x)d = j-i;
      else if(y<=i&&y<j)d = j-i;
      else if(i<=x&&y<=j)d = x-i+1+j-y;
      else if(i<=x&&x<=j&&j<=y)d = x-i+min(j-x,y-j+1);
      else if(x<=i&&i<=y&&y<=j)d = min(y-i,i-x+1)+j-y;
      else if(x<=i&&j<=y)d = min(j-i,i-x+1+y-j);
      else {cout << "no";return 0;}
      //cout << d <<" ";
      k.at(d) ++;
      j ++;
      }



  }
  rep(i,n)cout<<k.at(i)<<endl;
  
  

}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  v[n] = -1;  // 最後用

  int ren = 1, ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == v[i + 1]) {
      ren++;
    } else {
      ans += ren / 2;
      ren = 1;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import permutations

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n,m,r= map(int,input().split())
moku = list(map(int,input().split()))
d = [[float("inf")]*n for i in range(n)] 

for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
p = warshall_floyd(d)

a = [i for i in range(r)]
zyun = list(permutations(a))

ans = 10**9
for i in zyun:
    cou = 0
    for j in range(r-1):
        cou += p[moku[i[j]]-1][moku[i[j+1]]-1]
    ans = min(ans,cou)
print(ans)

Measured memory_bytes: 80620
#!/usr/bin/env python3

import collections
import functools


MOD = 10 ** 9 + 7
INF = MOD


def product_mod(seq, mod=MOD):
    return functools.reduce(lambda x, y: x * y % mod, seq, 1) % mod


Mountain = collections.namedtuple("Mountain", "ub lb")


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    ys = [int(y) for y in input().split()]
    ms = [Mountain(INF, 1) for _ in range(n)]
    ns = [Mountain(INF, 1) for _ in range(n)]
    ms[0] = Mountain(xs[0], xs[0])
    ns[-1] = Mountain(ys[-1], ys[-1])
    for idx in range(1, n):
        if xs[idx - 1] < xs[idx]:
            ms[idx] = Mountain(xs[idx], xs[idx])
        else:
            ms[idx] = Mountain(xs[idx], ms[idx].lb)
    for idx in range(n - 1)[::-1]:
        if ys[idx + 1] < ys[idx]:
            ns[idx] = Mountain(ys[idx], ys[idx])
        else:
            ns[idx] = Mountain(ys[idx], ns[idx].lb)
    hs = (Mountain(min(m.ub, n.ub), max(m.lb, n.lb)) for m, n in zip(ms, ns))
    ans = product_mod(max(h.ub - h.lb + 1, 0) for h in hs)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27596
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;
ll a[MAX],b[MAX];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
  	ll n,ans=0;cin>>n;
  	for(ll i=0;i<n;i++)
  	{
  		cin>>a[i];
  		ans^=a[i];
	}
  	for(ll i=0;i<n;i++)
  	{
  		b[i]=ans^a[i];
  	}
  	for(ll i=0;i<n;i++)
  		cout<<b[i]<<" ";
    return 0;
}


Measured memory_bytes: 6672
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int tree = sc.nextInt();
        int look = sc.nextInt();
        int people = 0;
        while (tree >= look * 2 + 1) {
            people++;
            tree -= look * 2 + 1;
        }
        if (tree > 0) {
            people++;
        }
        System.out.println(people);
    }
}


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


int main(){

	  while(1){
			int n; cin >> n;
			if(!n) break;

			vector<int> k(n);
			for(int i=0; i<n; i++) cin >> k[i];
			string s; cin >> s;

			int key=0;
			for(int i=0; i<s.size(); i++){

				  char ans = s[i];
				  for(int j=0; j<k[key]; j++){
						ans--;
						if( ans == 'a'-1 ) ans = 'Z';
						if( ans == 'A'-1 ) ans = 'z';
				  }
				  cout << ans ;
				  key++;
				  if( key == n ) key=0;
			}
			cout << endl;
	  }

}

Measured memory_bytes: 1204
h, w  = map(int, input().split())
l = [list(list(input())) for _ in range(h)]

search = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]

for i in range(h):
    for j in range(w):
        if l[i][j] == '.':
            tmp = 0
            for k in range(len(search)):
                if 0 <= i + search[k][0] <= h-1 and 0 <= j + search[k][1] <= w-1:
                    if l[i + search[k][0]][j + search[k][1]] == '#':
                        tmp += 1
            l[i][j] = str(tmp)

for k in range(h):
    print(''.join(l[k]))

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int T[100000], A[100000];
P range[100000];

const ll MOD = 1e9 + 7;

int main(){
    //*
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    /*/
      /*/

    int N;
    std::cin >> N;

    int mx = -1;
    for(int i=0;i<N;++i){
        std::cin >> T[i];

        if(T[i] > mx){
            range[i] = std::make_tuple(T[i], T[i]);
            mx = T[i];
        }else if(T[i] == mx){
            range[i] = std::make_tuple(1, mx);
        }
    }

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    mx = -1;
    for(int i=N-1;i>=0;--i){
        if(A[i] > mx){
            if(fst(range[i]) <= A[i] && A[i] <= snd(range[i])){
                range[i] = std::make_tuple(A[i], A[i]);
                mx = A[i];
            }else{
                std::cout << 0 << std::endl;
                return 0;
            }
        }else if(A[i] == mx){
            if(mx < fst(range[i])){
                std::cout << 0 << std::endl;
                return 0;
            }

            range[i] = std::make_tuple(fst(range[i]), min(mx, snd(range[i])));
        }
    }

    ll res = 1ll;
    for(int i=0;i<N;++i){
        res = res * (snd(range[i]) - fst(range[i]) + 1) % MOD;
    }

    std::cout << res << std::endl;
}


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

using namespace std;

const int MAXN = 100005;

typedef pair<int, int> pii;
#define fi first
#define se second

vector<pii> G[MAXN];

int mark[MAXN];

int n, u, v, w;

void dfs(int o, int p = 0)
{
    for (auto x : G[o])
    {
        if (x.fi == p)
            continue;
        if (x.se % 2 == 1)
            mark[x.fi] = (mark[o] ^ 1);
        else
            mark[x.fi] = mark[o];
        dfs(x.fi, o);
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        cin >> u >> v >> w;
        G[u].push_back(pair<int, int>(v, w));
        G[v].push_back(pair<int, int>(u, w));
    }
    mark[1] = 0;
    dfs(1);
    for (int i = 1; i <= n; i++)
        cout << mark[i] << endl;
    return 0;
}



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

int main(void)
{
    int n;
    while (cin >> n && n != 0) {
        int s;
        int max_value = INT_MIN;
        int min_value = INT_MAX;
        int sum = 0;
        for (int i = 0; i < n && cin >> s; i++) {
            max_value = max(max_value, s);
            min_value = min(min_value, s);
            sum += s;
        }
        cout << (sum - max_value - min_value) / (n - 2) << endl;
    }
}



Measured memory_bytes: 3072