akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

// https://atcoder.jp/contests/abc165/tasks/abc165_c
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();
		sc.close();


		long x = b-1L;
		if(x>n) {
			x = n;
		}


		System.out.println(a*x/b-a*(x/b));


	}
}


Measured memory_bytes: 27044
#include <stdio.h>
int main(void)
{
	int a,b;
	int c[28];
	for(a=0;a<28;a++){
		scanf("%d",&c[a]);
	}
	for(a=1;a<31;a++){
		for(b=0;b<28;b++){
			if(a==c[b]){
				break;
			}
			else if(a!=c[b]&&b==27){
				printf("%d\n",a);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
struct edge {
    int to, cost;
};
int n, b, c;
int a[10000];
const int N = pow(10,5)+1;

vector<bool> isp(N+1, true);
//エラトステネスの篩
void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    cin >> Q;
    vector<pair<int,int> > q;  
    sieve();
    for (int i = 0; i < Q; i++)
    {
        int tempa, tempb;
        cin >> tempa>>tempb;
        q.push_back(make_pair(tempa,tempb));
    }
    vector<ll> sum(100001);
    sum[0]=0;
    int count=0;
    for(int i=1;i<=100000;i+=2){
        if(isp[i]==true&&isp[(i+1)/2]==true)
            count++;

        sum[i]=count;
        //cout<<sum[i]<<"\n";
    }
    for (int i = 0; i < Q; i++)
    {
        //cout<<sum[q[i].second]<<" "<<sum[max(q[i].first-2,0)]<<"\n";
        cout<<sum[q[i].second]-sum[max(q[i].first-2,0)]<<"\n";
    }
    
}


Measured memory_bytes: 2420
import sys
sys.setrecursionlimit(int(1e6))

N, K, Q = list(map(int, input().split()))

scores = [0] * N
for i in range(Q):
    j = int(input()) - 1
    scores[j] += 1

max_score = max(scores)
# 正解者以外のポイントが1減る
for s in scores:
    score = K - (Q - s)
    if score <= 0:
        print('No')
    else:
        print('Yes')


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

int main(){
	int n;

	cin >> n;

	vector<int> a(n), b(n);
	vector<int> aeat(n), beat(n);
	vector<int> happy(n);
	vector<size_t> indices(n);
	iota(indices.begin(), indices.end(), 0);

	long asum = 0, bsum = 0;

	for(int i = 0; i < n; i++){
		cin >> a.at(i) >> b.at(i);
		happy.at(i) = a.at(i) + b.at(i);
	}

	sort(indices.begin(), indices.end(), [&happy](size_t i1, size_t i2){
		return happy[i1] > happy[i2];
	});

	for(int i = 0; i < n; i++){
		if(i % 2 == 0){
			asum += a.at(indices.at(i));
		}
		else{
			bsum += b.at(indices.at(i));
		}
	}

	cout << asum - bsum << endl;

}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve() {
  float N; cin >> N;
  cout << ceil(N/2) / N << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class ASandglass2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int t = in.nextInt();
            if (x > t) {
                out.println(x - t);
                return;
            }
            out.println(0);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n, k; cin >> n >> k;
  vector<int> h(n+k);
  for(int i=0; i<n; ++i) cin >> h[i];

  long long INF = 1LL<<60;
  vector<long long> dp(n+k,INF);
  dp[0] = 0;
  for(int i=0; i<n; ++i) {
    for(int j=1; j<=k; ++j) {
      dp.at(i+j) = min(dp.at(i+j), dp.at(i) + abs(h.at(i)-h.at(i+j)));
    }
  }
  cout << dp.at(n-1) << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 4520
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        string S = cin.next();
        string S1 = S.Substring(0, N);

        Dictionary<string, int> dic = new Dictionary<string, int>();
        for (int i = 0; i < (1 << N); i++)
        {
            StringBuilder sa = new StringBuilder();
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < N; j++)
            {
                if (((i >> j) & 1) == 0) sa.Append(S1[j]);
                else sb.Append(S1[j]);
            }
            string SS = sa.ToString() + "-" + sb.ToString();
            if (!dic.ContainsKey(SS)) dic[SS] = 0;
            dic[SS]++;
        }

        long ans = 0;

        for (int i = 0; i < (1 << N); i++)
        {
            StringBuilder sa = new StringBuilder();
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < N; j++)
            {
                if (((i >> j) & 1) == 0) sa.Append(S[2 * N - j - 1]);
                else sb.Append(S[2 * N - j - 1]);
            }
            string SS = sa.ToString() + "-" + sb.ToString();
            if (dic.ContainsKey(SS)) ans += dic[SS];
        }

        Console.WriteLine(ans);
    }

}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 48268
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner s=new Scanner(System.in);
        long n=s.nextLong();
        long k=s.nextLong();
        long ss=s.nextLong();
        if(ss<k){
            System.out.println((long)Math.floor((long)((long)ss*(long)n/(long)k) ));
        }
        else{
            long a1= (long) Math.floor( (long)((long)(k-1)*(long)n/(long)k) );
            long a2=(long) ((long)Math.floor( (long)((long)(k)*(long)n/(long)k))-(long)n);
            if(a1>a2 ) {
                System.out.println(a1);
            }else{
                System.out.println(a2);
            }
        }}}

Measured memory_bytes: 27092
H, W = map(int, input().split())

box = []
for i in range(H):
    a = [j for j in input()]
    if all(j == '.' for j in a):
        pass
    else:
        box.append(a)

idx = []
for i in range(len(box[0])):
    ct = 0
    for j in box:
        if j[i] == '.':
            ct += 1
    if ct == len(box):
        idx.append(i)

for i in box:
    for j in range(len(i)):
        if j < len(i)-1:
            if j in idx:
                pass
            else:
                print(i[j], end='')
        else:
            if j in idx:
                print()
            else:
                print(i[j])


Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

#define f(i,n) for(int i = 0; i < n; i++)
#define rf(i,n) for(int i = n - 1; i >= 0; i--)

const int N = 1000000007;

int h, w, nr = 1;
char ch;
//vector< vector<int> > dp;
// vector< vector<char> > a;
int dp[1005][1005];
string a[1005];

int main (){
  cin >> h >> w;

  //dp = vector<vector<int>> (w + 1, vector<int> (h + 1, 0));
  //a = vector<vector<char>> (w + 1, vector<char> (h + 1, 0));


  f( i, h)
    cin >> a[i];

  rf(i, h)
    rf(j, w){
      if (a[i][j] == '#')
       dp[i][j] = 0;
      else if (i == h - 1 && j == w - 1)
        dp[i][j] = 1;
      else if (i == h - 1)
        dp[i][j] = dp[i][j + 1];
      else if (j == w - 1)
        dp[i][j] = dp[i + 1][j];
      else
        dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % N;
    }

    cout << dp[0][0];

  return 0;
}


Measured memory_bytes: 5248
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        List<Integer> list1 = new LinkedList<>();
        
        for(int i = 0; i < N; i++){
            list1.add(sc.nextInt());
        }
        
        boolean changeFlag = true;
        while(changeFlag){
            changeFlag = false;
            Collections.sort(list1);
            int min = list1.get(0);
            
            List<Integer> list2 = new LinkedList<>();   
            list2.add(min);
            for(int x : list1){
                if( x % min == 0) continue;
                if( x % min < min) changeFlag = true;
                list2.add(x % min);
            }

            list1 = list2;
        }
        
        Collections.sort(list1);
        
        System.out.println(list1.get(0));

    }
}


Measured memory_bytes: 62252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct UnionFind {
  vector<int> par, s;
  vector<ll> cost;
  UnionFind(int n=2e5) { init(n); }
  void init(int n) { 
    s.assign(n, 1); par.resize(n); 
    iota(par.begin(), par.end(), 0);
    cost.resize(n);
  }
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y], cost[y] = cost[x] + cost[y];
    else par[y] = x, s[x] = s[x] + s[y], cost[x] = cost[x] + cost[y];
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return s[find(x)]; }
};

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n);
    REP(i, n) cin >> x[i];
    vector<ll> a(m), b(m), y(m);
    vector<vector<PII>> g(n);
    REP(i, m) {
        cin >> a[i] >> b[i] >> y[i];
        a[i]--, b[i]--;
        g[a[i]].push_back({b[i], i});
        g[b[i]].push_back({a[i], i});
    }

    vector<ll> ord(m);
    iota(ALL(ord), 0LL);
    sort(ALL(ord), [&](ll l, ll r){ return y[l] < y[r]; });

    // 重みがy[i]以下の辺が全て追加された状態 
    // 辺iが属する連結成分の頂点重みがy[i]以上 → iから重みy[i]以下の辺をたどって到達できる辺は残せる 
    vector<ll> ok;
    UnionFind uf(n);
    REP(i, n) uf.cost[i] = x[i];
    for(auto i: ord) {
        uf.unite(a[i], b[i]);
        if(uf.cost[uf.find(a[i])] >= y[i]) ok.push_back(i);
    }
    dump(ok);

    // 残せる辺の和集合を取る
    ll ret = 0;
    vector<bool> used(m);
    function<void(ll,ll)> dfs = [&](ll v, ll ub) {
        for(auto to: g[v]) {
            if(y[to.second] <= ub && !used[to.second]) {
                ret++;
                used[to.second] = true;
                dfs(to.first, ub);
            }
        }
    };
    reverse(ALL(ok));
    for(auto i: ok) dfs(a[i], y[i]);

    cout << m-ret << endl;    

    return 0;
}

Measured memory_bytes: 20340
#include<bits/stdc++.h>
using namespace std;
#define int long long
int r,g,b,n,ans;
signed main()
{
	cin>>r>>g>>b>>n;
	for(int i=0;i<=n/r;i++)
		for(int j=0;j<=n/g;j++)
		{
			int B=n-r*i-g*j;
			if(B>=0&&B%b==0)
				ans++;
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;


int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ans = 0;
    for(int i=1;i<n;i++){
        if(a[i]>=a[i-1])continue;
        ans += a[i-1]-a[i];
        a[i]=a[i-1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4760
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = min(a)+min(b)

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1]+b[y-1]-c)

print(ans)


Measured memory_bytes: 70764
#include <stdio.h>
#include <math.h>
int trianglechecker(int x, int y, int z);
int main(void){
    int loop,len1,len2,len3,Len1,Len2,Len3;
    int f=0;
    scanf("%d", &loop);
    for(int i=0;i<loop;i++)
    {
        scanf("%d%d%d", &len1, &len2, &len3);
        f=trianglechecker(len1,len2,len3);
        if(f == 1)
        {
            printf("YES\n");
        }
        if(f == 0)
        {
            printf("NO\n");
        }
    }
    return 0;
}
int trianglechecker(int x, int y, int z)
{
    if(x * x == y * y + z * z){
        return 1;
    }
    if(y * y == x * x + z * z){
        return 1;
    }
    if(z * z == y * y + x * x){
        return 1;
    }
    return 0;
}

Measured memory_bytes: 1008
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.compute(scanner.nextInt(), (key, value) -> value == null ? 1 : value + 1);
        }
        System.out.println(f(map) ? "Yes" : "No");
    }

    static boolean f(Map<Integer, Integer> map) {
        int s = map.size();
        int[][] a = new int[s][2];
        int i = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            a[i][0] = entry.getKey();
            a[i++][1] = entry.getValue();
        }

        if (s > 3) {
            return false;
        }

        Arrays.sort(a, Comparator.comparingInt(array -> array[0]));

        if (s == 1) {
            return a[0][0] == 0;
        } else if (s == 2) {
            return a[0][0] == 0 && a[0][1] * 2 == a[1][1];
        } else {
            return a[0][1] == a[1][1] && a[1][1] == a[2][1] && (a[0][0] ^ a[1][0] ^ a[2][0]) == 0;
        }
    }
}

Measured memory_bytes: 61568
#include <stdio.h>

int main (void)
{

  int N=0,a=0,b=0,c=0;
  
  scanf("%d",&N);
  
  a=N/100;
  
  b=(N-100*a)/10;
    
  c=N-100*a-10*b;
  
  if(a!=7)
  {
  	if(b!=7)
  	{
    	if(c!=7)
        {
        	printf("No");
        }
      	else
        {
        	printf("Yes");
        }
    }
    else
    {
    	printf("Yes");
    }
  }
  else
  {
  	printf("Yes");
  }
  return 0;
}

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

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

template <int64_t mod>
struct modint {
  int64_t a;
  modint(int64_t a = 0) {
    a %= mod;
    if (a < 0) a += mod;
    this->a = a;
  }
  modint operator+(modint rhs) { return modint(a + rhs.a); }
  modint operator-(modint rhs) { return modint(a - rhs.a); }
  modint operator*(modint rhs) { return modint(a * rhs.a); }
  modint pow(modint base, int64_t exp) {
    auto b = base;
    auto res = modint(1);
    while (exp > 0) {
      if (exp & 1) { res = res * b; }
      b = b * b;
      exp = exp / 2;
    }
    return res;
  }
  modint inv() { return pow(*this, mod - 2); }
  modint operator/(modint rhs) { return (*this) * rhs.inv(); }
};

using mint = modint<1000000000 + 7>;
mint solve(int r, int c) {
  auto n = r + c + 2;
  vector<mint> fac(n), inv(n);
  fac[0] = 1;
  for (int i = 1; i < n; i++) {
    // fac[i] = mint(i) * fac[i - 1];
    fac[i] = fac[i - 1] * i;
  }
  inv[n - 1] = fac[n - 1].inv();
  for (int i = n - 2; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
  }
  auto binom = [&](int a, int b) -> mint {
    if (a < 0 or b < 0) return 0;
    if (a < b) return 0;
    return fac[a] * inv[b] * inv[a - b];
  };
  auto countPath = [&](int a, int b) { return binom(a + b, b); };
  auto res = mint(0);
  for (int i = 0; i <= r; i++) {
    res = res + countPath(i + 1, c);
  }
  return res;
}

int main() {

  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  auto ans = solve(r2, c2);
  ans = ans - solve(r1 - 1, c2);
  ans = ans - solve(r2, c1 - 1);
  ans = ans + solve(r1 - 1, c1 - 1);
  cout << ans.a << endl;

  return 0;
}


Measured memory_bytes: 31552
l=list(str(input()))
l.insert(0,"S")
ans=0
tot=0
for i in range(4):
    if(l[i]=="R"):
        if(l[i-1]=="R"):
            ans+=1
            if(ans>tot):
                tot=ans
        elif(l[i-1]=="S"):
            ans=1
            if(ans>tot):
                tot=ans
print(tot)

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

bool solve(string s)
{
    stack<char> bracket;

    for(int i=0; i < s.size(); i++)
    {
        switch(s[i])
        {
            case '(' :
            case '[' :
                bracket.push(s[i]);
                break;
            case ')' :
                if(bracket.empty() || bracket.top() != '(')
                {
                    return false;
                }
                bracket.pop();
                break;
            case ']' :
                if(bracket.empty() || bracket.top() != '[')
                {
                    return false;
                }
                bracket.pop();
                break;
            default :
                break;
        }
    } 
    
    return bracket.empty();
}

int main(void)
{
    for(;;)
    {
        string s;
        getline(cin, s);

        if (s == ".")
        {
            break;
        }
        else
        {
            cout << (solve(s) ? "yes" : "no") << endl;
        }
    }
    return 0;
}



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

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> tree(N+1, vector<int>());
    int a, b;
    for (int i = 0; i < N-1; i++) {
        scanf("%d", &a);
        scanf("%d", &b);
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> counter(N+1, 0);
    int p, x;
    for (int i = 0; i < Q; i++) {
        scanf("%d", &p);
        scanf("%d", &x);
        counter[p] += x;
    }
    queue<int> q;
    q.push(1);
    vector<bool> check(N+1, false);
    int now;
    while (!q.empty()) {
        now = q.front();
        q.pop();
        check[now] = true;
        for(int nxt : tree[now]) {
            if (!check[nxt]) {
                q.push(nxt);
                counter[nxt] += counter[now];
            }
        }       
    }
    for (int i = 1; i <= N; i++) {
        printf("%d ", counter[i]);
    }
}

Measured memory_bytes: 15604
#include <iostream>
#include <vector>
#include <algorithm>

int solve(int n,std::vector<int> v) {
  std::sort(v.begin(),v.end());
  std::vector<int> cv(n,0);
  const int weight=10;
  const auto le=v[n-1];
  int ans=n;
  for ( int i=0; i<n; i++ ) {
    if ( cv[i] ) {
      ans-=1;
      continue;
    }
    auto e=v[i];
    if ( i<n-1 && v[i+1]==e )
      ans-=1;
    int d=le/e;
    if ( d*weight > n-i ) {
      for ( int j=i+1; j<n; j++ )
        if ( v[j]%e==0 )
          cv[j]=1;
    }
    else {
      int j=i+1;
      for ( ; j<n&&v[j]==e; j++ )
        cv[j]=1;
      for ( int k=2; k<=d; k++ ) {
        auto b=e*k;
        auto it=std::lower_bound(v.begin()+j,v.end(),b);
        while ( it!=v.end() && *it==b ) {
          cv[std::distance(v.begin(),it)]=1;
          it++;
        }
        j=std::distance(v.begin(),it);
      }
    }
  }
  return ans;
}
int main() {
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for ( auto &e: v ) {
    std::cin >> e;
  }
  std::cout << solve(n,v) << std::endl;
}

Measured memory_bytes: 5632
from fractions import gcd
from functools import reduce

def lcm_base(x,y):
  return (x * y) // gcd(x,y)

def lcm(numbers:list):
  return reduce(lcm_base,numbers,1)

n = int(input())
T = [int(input()) for _ in range(n)]

print(lcm(T))

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

int main(){
  string S,T;
  cin >> S >> T;
  if((T.size()-S.size())==1 && S==T.substr(0,S.size())){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,X[5001],R[5001],cnt[5001],sumr[5001];
ll dp[5001][5001];
ll dp2[2][5001];
ll tot=0,p=0,K;
vector<int> g[5001];

void dfs(int v,int pre){
  cnt[v]=1; sumr[v]=R[v];
  for(int nv : g[v]){
    if(nv==pre)continue;
    dfs(nv,v);
    cnt[v]+=cnt[nv]; sumr[v]+=sumr[nv];
  }
  int crt=0,nxt=1;
  rep(j,cnt[v]+1)dp2[crt][j]=INF;
  dp2[crt][0]=0;
  for(int nv : g[v]){
    if(nv==pre)continue;
    rep(j,cnt[v]+1)dp2[nxt][j]=INF;
    rep(j,cnt[v]+1){
      if(dp2[crt][j]==INF)break;
      rep(k,cnt[nv]+1){
        if(j+k<=cnt[v])minch(dp2[nxt][j+k],dp2[crt][j]+dp[nv][k]+llabs(sumr[nv]-k));
        else break;
      }
    }
    swap(crt,nxt);
  }
  rep(j,cnt[v]+1){
    dp[v][j]=dp2[crt][j];
    if(j>0)minch(dp[v][j],dp2[crt][j-1]);
  }
}

int main(){
  scanf("%lld",&N);
  rep(i,N){
    scanf("%lld",X+i);
    p+=X[i]; tot+=X[i];
  }
  p/=N; K=tot-N*p;
  rep(i,N){
    R[i]=X[i]-p;
  }
  rep(i,N-1){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    g[a].push_back(b); g[b].push_back(a);
  }
  dfs(0,-1);
  cout<<dp[0][K]<<endl;
  return 0;
}



Measured memory_bytes: 121020
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
int N,Q;
vector<int> A(1100);

int main() {
	cin >> N;
	rep(i, N) cin >> A[i];
	cin >> Q;
	rep(i, Q) {
		int b, e, k;
		cin >> b >> e >> k;
		
		int ans = count(A.begin() + b, A.begin() + e, k);
		cout << ans << endl;
	}
	return 0;
}





Measured memory_bytes: 3100
import java.util.*;

public class Main{
  static int p = 1000000007;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int Z = X+Y;
    int d = Z/3;
    int e = (d-Math.abs(X-Y))/2;
    if(Z%3 != 0 || e < 0){
      System.out.println(0);
      return;
    }

    long A = 1;
    long B = 1;
    for(int i = 0; i < e; i++){
      A *= d-i;
      A %= p;
      B *= e-i;
      B %= p;
    }
    long ans = A * inv(B, p-2) % p;
    System.out.println(ans);
  }  
  public static long inv(long n, int k){
    if(k == 0){
      return 1;
    }
    
    if(k%2 == 0){
      long l = inv(n, k/2);
      return l * l % p;
    }else{
      return n * inv(n, k-1) % p;
    }
  }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
signed main(){
  int n;
  cin>>n;
  V<int> a(n);
  fo(i,n){
    cin>>a[i];
  }
  Sort(a);
  V<int> b(100010);
  fo(i,n){
    b[a[i]]++;
  }
  int ans=0;
  fo(i,100010){
    if(i==0){
      ans=max(ans,b[0]+b[1]);
      continue;
    }
    if(i==100009){
      ans=max(ans,b[i]+b[i-1]);
      continue;
    }
    int c=0;
    fo(j,3){
      c+=b[i+j];
    }
    ans=max(ans,c);

  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#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 <math.h> // sqrt
#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 <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    ll N, M, ans;
    cin >> N >> M;
    if (N * 2 > M) {
        ans = floor(M / 2);
    }
    else {
        ans = N;
        M -= 2 * N;
        ans += floor(M / 4);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	int n;
	int ans=0;
	std::vector<int> aList;

	std::cin>>n;
	aList.resize(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end());

	int curNum= aList[0];
	int count= 1;
	std::vector<int> finalCount;

	for(int i=1; i<n; i++){
		if(curNum!= aList[i]){
			curNum= aList[i];
			finalCount.push_back(count);
			count= 0;
		}

		count++;
	}

	finalCount.push_back(count);

	for(int i=0; i<finalCount.size(); i++)
		if(finalCount[i]%2==1)
			ans++;

	std::cout<<ans<<std::endl;

	return 0;
		
	
}


Measured memory_bytes: 1276
#from itertools import chain 

S = input()

state = 'R'
var = 0
lst = []
for i in range(len(S)):
  if S[i] == state:
    var += 1
  else:
    state = S[i]
    lst.append(var)
    var = 1
else:
  lst.append(var)  
#print(lst)

lst2 = []
for i in range(len(lst)//2):
  var_R = lst[2*i]
  var_L = lst[2*i+1]
  lst2.append((var_R+1)//2 + var_L//2)
  lst2.append(var_R//2 + (var_L+1)//2)  
#print(lst2)

ans = []
for i in range(len(lst)//2):
  var1 = lst[2*i]
  var2 = lst[2*i+1]
  var3 = lst2[2*i]
  var4 = lst2[2*i+1]
  ans.extend([0]*(var1-1))
  ans.append(var3)
  ans.append(var4)
  ans.extend([0]*(var2-1))
  
#print(ans)
ans = list(map(str, ans))
print(' '.join(ans))

Measured memory_bytes: 11892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    int L[n];
    int sum=0;
    for (int i=0;i<n;i++) {
        cin >> L[i];
        sum += L[i];
    }
    sort(L,L+n,greater<int>());
    cout << ((L[0]<sum-L[0])? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

string words[4]={"dream","dreamer","erase","eraser"};

int main(){
	string S;
	cin >> S;
	reverse(S.begin(),S.end());
	for(int i=0; i<4; i++)
		reverse(words[i].begin(),words[i].end());
	bool can = true;
	for(int i=0; i<S.size();){
		bool can2=false;
		for(int j=0; j<4; j++){
			string d=words[j];
		    if(S.substr(i,d.size())==d){
				i+=d.size();
				can2=true;
			}
		}
		if(!can2){
			can=false;
			break;
		}
	}
	if(can)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
typedef pair<int, int> pii;
typedef vector< pii > PArray;

int n, m;
int poyo[1010][110];

void solve() {
	int cnt[110] = { 0 };
	for_(i,0,m) for_(j,0,n) cnt[i] += poyo[j][i];
	
	PArray vp;
	for_(i,0,m) vp.push_back(pii(cnt[i], -(i + 1)));
	sort(allof(vp));
	
	for_rev(i,m-1,0) {
		if (i > 0) printf("%d ", -vp[i].second);
		else printf("%d\n", -vp[i].second);
	}
}

int main() {
	while (scanf("%d %d", &n, &m), n) {
		for_(i,0,n) for_(j,0,m) scanf("%d", &poyo[i][j]);
		solve();
	}
	return 0;
}

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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define endl "\n"
#define elif else if
#define vint vector<signed>
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;
#define all(a) a.begin(),a.end()

signed main(){
  int n;
  cin>>n;
  int base=-2;
  vint a;
  while(n){
    int r=abs(n%base);
    n=(n-r)/base;
    a.pb(r);
  }
  if(a.size()==0)a.pb(0);
  reverse(all(a));
  for(auto i:a)cout<<i;
  cout<<endl;
  
  return 0;
}


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

int main()
{
    long long num[260],i,j;
    for(i=0;i<=242;i++){
        num[i]=(i-120)*(i-120)*(i-120)*(i-120)*(i-120);
    }
    long long n,flag=0;
    scanf("%lld",&n);
    for(i=242;i>=0;i--){
        for(j=242;j>=0;j--){
            long long t;
            t=n+num[j];
            if(num[i]==t){
                flag=1;
                break;
            }

        }
        if(flag)
                break;
    }
    printf("%lld\n%lld",i-120,j-120);
    return 0;
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://cf16-final-open.contest.atcoder.jp/tasks/codefestival_2016_final_b>
問題文============================================================
 ある年のCODE FESTIVALの決勝では N 問の問題が出題されました。
 
 i(1≦i≦N) 番目の問題の配点は i 点です。
 
 高橋くんは、このコンテストでちょうど N 点を取りたいと思い、そのために解く問題の集合をどうするかを考えています。
 
 配点が高い問題は難しいので、解く問題の配点のうちの最大値が最小になるようにしようと考えました。
 
 高橋くんが解くべき問題の集合を求めてください。
 

=================================================================

解説=============================================================

 1...Xまでの総和がNを越える時、
 Nは1...Xまでのいづれかのものを用いて作ることができる
 
 ex. X      : 1,2,3,4,5,...
     Cusum  : 1,3,6,10,15 ...
 
 15 => Σ{1..5}
 14 => 15 - "1"
 13 => 15 - "2"
 12 => 15 - "3"
 11 => 15 - "4"
 
 と考えるとそれは、そう(これは覚えておいたほうが良さそう）
 
 この前提をもとにすると、あらかじめ累積和で総和を求めておき、にぶたんすれば
 あるNに対して、log(N)で最小値が見つかる
 よって　Nlog(N) で全てのNについての最小値がわかる
 
 次に、その組み合わせに関しては、順番が関係ないので、
 求めた最小値の情報をもとに順番にたどっていけば良い
================================================================
*/
void solve(ll n,vector<ll>& dp){
    cout << dp[n] << endl;
    if(dp[n] != n) solve(n - dp[n],dp);
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    
    vector<ll> cusum(N+1,0);
    for(int i = 0; i < N;i++) cusum[i+1] = cusum[i] + i;
    vector<ll> dp(N+1,INF);
    for(int i = 1; i <= N;i++){
        dp[i] = lower_bound(cusum.begin(),cusum.end(),i) - cusum.begin() - 1;
    }
    solve(N,dp);
	return 0;
}


Measured memory_bytes: 156544
V,E = map(int,input().split())
dlist = [[0]*V for _ in range(V)]
dp = [[10**11]*V for _ in range(V)]
#0-kの頂点を使ってiからjまで行くときの最短経路
#k-1のときと同じ or i-k+k-j
#初期値はi-j

for _ in range(E):
  el = list(map(int,input().split()))
  dlist[el[0]][el[1]] = el[2]
  dp[el[0]][el[1]] = el[2]

for i in range(V):
  dp[i][i] = 0

for k in range(V):
  for i in range(V):
    for j in range(V):
      dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
  
for i in range(V):
  if dp[i][i] < 0:
    print("NEGATIVE CYCLE")
    exit()
      
for i in range(V):
  for j in range(V):
    if dp[i][j] >= 10**10:
      dp[i][j] = "INF"
      
for i in range(V):
  print(*dp[i])


Measured memory_bytes: 6544
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    vector <ll> as;
    vector <ll> bs;
    REP(i, n){
        ll a; ll b;
        cin >> a >> b;
        as.push_back(a);
        bs.push_back(b);
    }
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());

    ll low = as[n/2];
    if (n % 2 == 0){
        low += as[n/2 - 1];
    }
    ll high = bs[n/2];
    if (n % 2 == 0){
        high += bs[n/2 - 1];
    }

    cout << high - low + 1 << endl;
    return 0;
}

Measured memory_bytes: 6648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;

	cin >> a >> b >> n;

	if (b>n) {
		ans = a*n/b;
	} else {
		ans = a*(b-1)/b;
	}
	cout << ans << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;

  ll q;
  scanf("%lld", &q);

  // cout << q << endl;

  string pre = "";
  string post = "";

  bool reversed = false;

  for (ll i = 0; i < q; i++) {
    ll type;
    scanf("%lld", &type);

    if (type == 1) {
      reversed = !reversed;
    } else if (type == 2) {
      ll f;
      scanf("%lld", &f);
      string c;
      cin >> c;

      if (f == 1) {
        // pre
        if (!reversed) {
          pre += c;
        } else {
          post += c;
        }
      } else if (f == 2) {
        // post
        if (!reversed) {
          post += c;
        } else {
          pre += c;
        }
      } else {
        assert(0);
      }

    } else {
      assert(0);
    }
    // cout << type << endl;
  }
  // cout << "pre:" << pre << endl;
  // cout << "post:" << post << endl;

  string ans;
  if (!reversed) {
    reverse(pre.begin(), pre.end());
    ans = pre + s + post;
  } else {
    reverse(s.begin(), s.end());
    reverse(post.begin(), post.end());
    ans = post + s + pre;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1348
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            total=500*a+100*b+50*c
            if total==X:
                ans+=1

print(ans)   

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

struct edge{/*重み付き,有向*/
    int to , cost;/*toは接続先*/
    edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;


graph g;
ll n,m;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>m;
    g.resize(n);
    rep(i,m){
        ll in,inp,inc;
        cin>>in>>inp>>inc;
        in--;
        inp--;
        g[in].pb(edge(inp,-inc));
    }
    Vi dist(n,INF);
    bool flg = false;
    dist[0]=0;
    rep(i,n){
        rep(j,n){
            rep(k,g[j].size()){
                edge e = g[j][k];
                if(chmin(dist[e.to],dist[j]+e.cost)){
                    if(i==n-1){
                        dist[e.to] = -INF;
                    }
                }
            }
        }
    }
    if(dist[n-1]!=-INF)print(-dist[n-1]);
    else print("inf");
    return 0;
}

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

using namespace std;

#define F first
#define S second
#define MAX_N 1e5+10
#define inf 10000000

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vbl;

int main() {
  int n;
  cin >> n;
  ll p[n+1][3], dp[n+1][3];
  for (int i = 1 ; i <= n ; i++) {
    cin >> p[i][0] >> p[i][1] >> p[i][2];
    dp[i][0] = 0;
    dp[i][1] = 0;
    dp[i][2] = 0;
  }

  dp[1][0] = p[1][0];
  dp[1][1] = p[1][1];
  dp[1][2] = p[1][2];
  
  for (int i = 2 ; i <= n ; i++) {
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]);
    dp[i][0] += p[i][0];
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]);
    dp[i][1] += p[i][1];
    dp[i][2] = max(dp[i-1][0],dp[i-1][1]);
    dp[i][2] += p[i][2];
  }

  ll res = 0;
  
  for (int i = 0 ; i < 3 ; i++) {
    res = max(res,dp[n][i]);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	vector<int> a(N), b(N), c(N);
	REP(i, N) cin >> a[i];
	REP(i, N) cin >> b[i];
	REP(i, N) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	ll res = 0;
	REP(i, N) {
		res += (ll)(upper_bound(a.begin(), a.end(), b[i] - 1) - a.begin())
				* (c.end() - upper_bound(c.begin(), c.end(), b[i]));
	}
	cout << res << "\n";

	return 0;
}

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

int main(void){
  int y, m, d;
  char c1, c2;
  cin >> y >> c1 >> m >> c2 >> d;
  if(m < 5) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}


Measured memory_bytes: 256
// 失敗!!!!!!!!!

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define scn(n) scanf("%d", &n)
#define scns(s) scanf("%s", &s)
#define pri(n) printf("%d", n)
#define priln(n) printf("%d\n", n)
#define pris(s) printf("%s", s)
#define prisln(s) printf("%s\n", s)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const long MOD = 1000000007;

// 繰り返し自乗法（n^p をMODありで計算する）
ll modpow(ll n, ll p) {
  if (p == 0) return 1;
  ll x = modpow(n, p / 2);
  x = x * x % MOD;
  if (p % 2 == 1) x = x * n % MOD;
  return x;
}

// 組み合わせ nCk mod
// aが十分小さい場合
ll choose(int n, int a) {
  ll x = 1;
  ll y = 1;
  rep(i, a) {
    x = x * (n - i) % MOD; // 分子はn-i
    y = y * (i + 1) % MOD; // 分母はaの階乗
  }

  return x * modpow(y, MOD - 2) % MOD;
}

int main()
{
  int n, a, b;
  scn(n);
  scn(a);
  scn(b);

  ll ans = modpow(2, n);
  ans -= 1;
  if ((ans += MOD-choose(n, a)) >= MOD) ans -= MOD;
  if ((ans += MOD-choose(n, b)) >= MOD) ans -= MOD;
  pri(ans);

  return 0;
}


Measured memory_bytes: 256
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    if len(T) > 0:
        return min(T)
    else:
        return n  # Sは0のみまたは1のみで構成されていた

S = input()
print(d_WideFlip(S))

Measured memory_bytes: 5204
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long double, long double>;



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

  ll n;
  std::cin>>n;

  std::vector<P> point(n);
  rep(i,0,n){
    std::cin>>point[i].first>>point[i].second;
  }

  std::sort(all(point),[](P a,P b)->bool{return (std::atan2(a.second,a.first)<std::atan2(b.second,b.first));});

  std::vector<P> sum(n+1,{0.0l,0.0l});

  rep(i,0,n)sum[i+1]={sum[i].first+point[i].first,sum[i].second+point[i].second};

  long double ans=0.0l;

  rep(i,0,n+1){
    rep(j,0,n+1){

      P temp;
      if(i<=j){
        temp={sum[j].first-sum[i].first,sum[j].second-sum[i].second};
      }else{
        temp={sum[n].first+sum[j].first-sum[i].first,sum[n].second+sum[j].second-sum[i].second};
      }
      chmax(ans,std::hypot(temp.first,temp.second));
    }
  }

  std::cout<<std::setprecision(20)<<std::fixed;

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 256