akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	int h, w;
	int i, j, k;
	char p[52][53];
	int q[52][53] = {0};

	scanf("%d%d", &h, &w);

	for(i=0; i < h; i++){
		scanf("%s", &p[i+1][1]);
	}

	for(i=1; i <= h; i++){
		for(j=1; j <= w; j++){
			if(p[i][j] == '#'){
				for(k=-1; k <= 1; k++){
					q[i-1][j+k]++;
					q[i+1][j+k]++;
				}
				q[i][j-1]++;
				q[i][j+1]++;
			}
		}
	}


	for(i=1; i <= h; i++){
		for(j=1; j <= w; j++){
			if(p[i][j] == '#'){
				printf("%c", p[i][j]);
			}
			else{
				printf("%d", q[i][j]);
			}
		}
		printf("\n");
	}


return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

ll calc(ll x) {
  if (x == 0) return 0;
  return 1 + calc(x % __builtin_popcount(x));
}

int main() {
  in(ll, n);
  in(string, x);
  ll p = count(all(x), '1');

  map<ll, vector<ll>> mods_cache;
  auto getMods = [&](ll mod) -> auto& {
    if (mods_cache.count(mod) == 0) {
      vector<ll> m(n);
      m[0] = 1 % mod;
      for (ll i = 1; i < n; ++i) {
        m[i] = (m[i - 1] << 1) % mod;
      }
      mods_cache[mod] = m;
    }
    return mods_cache[mod];
  };

  auto getMod = [&](ll i, ll mod) { return getMods(mod)[n - 1 - i]; };

  map<ll, ll> get_sum_cache;
  auto getSum = [&](ll mod) {
    if (get_sum_cache.count(mod) == 0) {
      ll sum = 0;
      rep(i, n) if (x[i] == '1') sum += getMod(i, mod);
      get_sum_cache[mod] = sum;
    }
    return get_sum_cache[mod];
  };

  rep(i, n) {
    if (x[i] == '1') {
      if (p == 1) {
        out(0);
      } else {
        ll sum = getSum(p - 1);
        sum -= getMod(i, p - 1);
        sum %= p - 1;
        out(1 + calc(sum));
      }
    } else {
      ll sum = getSum(p + 1);
      sum += getMod(i, p + 1);
      sum %= p + 1;
      out(1 + calc(sum));
    }
  }
}


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

const int INF = 1000000000;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    vector<vector<int>> dp(N + 1, vector<int>(20001, INF));
    for (int i = 0; i <= N; i++) {
        dp[i][0] = 0;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 20000; j++) {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i]);
        }
    }

    int res = INF;
    for (int j = H; j <= 20000; j++) {
        res = min(res, dp[N][j]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 78592
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, k;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	long long tmp = n % k;
	long long ans = min(tmp, k - tmp);
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    for(int ia = 0; ia < n; ia++){
        cin >> a[ia];
        a[ia]--;
    }

    for(int ib = 0; ib < n; ib++){
        cin >> b[ib];
    }

    for(int ic = 0; ic < n - 1; ic++){
        cin >> c[ic];
    }

    int ans = 0;
    int previous = 100;
    for(int i = 0; i < n; i++){
        ans += b[a[i]];

        if(a[i] == previous + 1){
            ans += c[previous];
        }

        previous = a[i];
    }

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

Measured memory_bytes: 888
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
    if s=="1":
        cnt += 1
        A[i] = cnt
    else:
        cnt = 0
dp = 0
res = []
while dp+M <= N-1:
    t = M - A[dp+M]
    if t>0:
        dp += t
    else:
        print(-1)
        exit()
    res.append(t)
res.append(N-dp)
res.reverse()
print(*res)

Measured memory_bytes: 84464
// 解けてない
#include <bits/stdc++.h>
using namespace std;

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

  vector<int> vec(N);

  for (int i = 0; i < N; i++)
  {
    cin >> vec.at(i);
  }

  int minElement = *min_element(vec.begin(), vec.end());
  int maxElement = *max_element(vec.begin(), vec.end());

  int ans = 1000000000;

  for (int i = minElement; i <= maxElement; i++)
  {
    int tmpAns = 0;

    for (int j = 0; j < N; j++)
    {
      tmpAns += pow(vec.at(j) - i, 2);
    }

    ans = min(ans, tmpAns);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

vector<int> uf, usz;
int nc;

void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for(int i = 0; i < uf.size(); i++){
    uf[i] = i;
  }
}

int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b){
  a = find(a);
  b = find(b);

  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a){
  return usz[find(a)];
}

int main() {
	ll n;
	cin>>n;
	init(100100);
	vector<pair<ll,ll> > v;
	rep(i,0,n){
		ll x,y;
		cin>>x>>y;
		v.pb(mp(x,y));
	}
	sort(all(v));
	rep(i,0,v.sz-1){
		if(v[i].fi==v[i+1].fi){
			union_(v[i].se,v[i+1].se);
		}
	}
	vector<set<ll> > vs(100100,set<ll>());
	rep(i,0,v.sz){
		ll x1 = v[i].fi;
		ll y1 = find(v[i].se);
		vs[y1].insert(x1);
	}
	vector<vector<ll> > vv(100100,vector<ll>());
	rep(i,0,vs.sz){
		vector<ll> v1(all(vs[i]));
		vv[i] = v1;
	}
	ll ans = 0;
	rep(i,0,vs.sz){
		if(vs[i].sz==0)continue;
		ll a = get_size(i);
		if(a==1)continue;
		ll ans1 = a*vs[i].sz;
		ans += ans1;
	}
	rep(i,0,v.sz){
		ll x1 = v[i].fi;
		ll y1 = v[i].se;
		ll a = find(y1);
		ll b = get_size(y1);
		if(b==1)continue;
		set<ll>::iterator itr = vs[a].find(x1);
		if(itr!=vs[a].end()){
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12776
#include <bits/stdc++.h>
using ull = unsigned long long;
using namespace std;

const ull B = 100000007;

ull Pow(ull a, ull b) {
	ull res = 1;
	for (ull i = 0; i < 0x40;i++) {
		if (b & (1ull << i)) {
			res *= a;
		}
		a *= a;
	}
	return res;
}

int main()
{
	ull n, m, l = 0, r = 0;
	ull hash;
	string S, cmd;
	set<ull> hass;
	cin.sync_with_stdio(false);
	cin >> n >> m >> S;
	hash = S[0];
	while (m--) {
		cin >> cmd;
		if (cmd == "L++") {
			hash -= Pow(B, r - l) * S[l];
			l++;
		}
		else if (cmd == "L--") {
			l--;
			hash += Pow(B, r - l) * S[l];
		}
		else if (cmd == "R++") {
			r++;
			hash = hash * B + S[r];
		}
		else if (cmd == "R--") {
			hash = (hash - S[r]) * Pow(B, 0xffffffffffffffffull);
			r--;
		}
		hass.insert(hash);
	}
	cout << hass.size() << endl;
	return 0;
}

Measured memory_bytes: 17224
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	s := sc.Text()
	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())

	var fc rune
	fi := len(s)
	for i, c := range s {
		if c != '1' {
			fc = c
			fi = i
			break
		}
	}

	if fi+1 <= k {
		fmt.Println(string(fc))
	} else {
		fmt.Println(1)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<vb> g(n, vb(n, false));
  vi v;
  rep(i, n) v.push_back(i);
  int ans = 0;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a][b] = g[b][a] = true;
  }
  do {
    if(v[0] != 0) continue;
    bool ok = true;
    rep(k, n - 1) {
      int i = v[k];
      int j = v[k + 1];
      if(!g[i][j]) ok = false;
    }
    if(ok) ans++;
  } while(next_permutation(all(v)));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  ll n,m,x;
  
  cin >> n >> m >> x;
  vector<vector<ll>> a(n,vector<ll>(m));
  vector<ll> c(n);
  
  REP(i,n){
    cin >> c.at(i);
    REP(j,m){
      cin >> a.at(i).at(j);
    }
  }
  
  ll mins = INF;
  for(int bit=0; bit<(1<<n); bit++){
    vector<ll> flag(n,0);
    vector<ll> syuju(m,0);
    ll minsc=0;
    
    for(int i=0; i<n; i++){
      if(bit&(1<<i)){
        flag.at(i) = 1;
      }
    }
    
    for(int i=0;i<n; i++){
      if(flag.at(i)==1){
        for(int j=0; j<m; j++){
          syuju.at(j) += a.at(i).at(j);
        }
        minsc += c.at(i);
      }
    }
    
    bool cd = true;
    for(int i=0; i<m; i++){
      if(syuju.at(i)<x){
        cd = false;
      }
    }
    
    if(cd){
      if(mins>=minsc){
        mins = minsc;
      }
    }
  }
  
  if(mins!=INF){
    cout << mins << endl;
  }else{
    cout << -1 << endl;
  }
}



Measured memory_bytes: 3644
using System;

namespace A___Dividing_a_String
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var K = 1;
            var previous = S[0].ToString();
            var now = "";
            for (int i = 1; i < S.Length;i++)
            {
                now += S[i];
                if (now != previous)
                {
                    K += 1;
                    previous = now;
                    now = "";
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine(K);
        }
    }
}


Measured memory_bytes: 15832
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 999999999ll
#define MIN -999999999ll

int main() {
  ll n,q;
  cin>>n;
  map<string,ll> data;
  loop(i,n){
    string act,name;
    cin>>act>>name;
    if(act=="insert"){
      data[name]++;
    }
    if(act=="find"){
      if(data[name]!=0){
        cout<<"yes"<<endl;
      }
      else{
        cout<<"no"<<endl;
      }
    }
  }

}


Measured memory_bytes: 52496
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

const double ERR = 1e-9;

typedef pair<double, double> XY;

XY solveeq(double a, double b, double c, double d, double e, double f) {
    double x, y;
    x = (c*e - b*f)/(a*e - b*d);
    y = (a*f - c*d)/(a*e - b*d);
    return make_pair(x,y);
}

XY getcenter(double x1, double y1, double x2, double y2, double x3, double y3) {
    return solveeq((x2-x1)/(y2-y1+ERR), 1, (x2*x2-x1*x1)/2/(y2-y1+ERR)+(y1+y2)/2, (x3-x2)/(y3-y2+ERR), 1, (x3*x3-x2*x2)/2/(y3-y2+ERR)+(y2+y3)/2);
}

double getradius(XY center, double x1, double y1) {
    return sqrt((x1-center.first)*(x1-center.first) + (y1-center.second)*(y1-center.second));
}

int main() {
    double x1,y1,x2,y2,x3,y3;
    int n;
    cin >> n;
    REP(i,n) {
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        XY center = getcenter(x1, y1, x2, y2, x3, y3);
        double radius = getradius(center, x1, y1);
        printf("%.3f %.3f %.3f\n", center.first+ERR, center.second+ERR, radius+ERR);
    }
    return 0;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e6) + 17;

int n;
int a[MAXN], p[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

void solve() {
    forn (i, n)
        p[a[i]] = i;

    int ans = 1;

    for (int l = 1; l <= n; ) {
        int r = l + 1;
        for (; r <= n && p[r] > p[r - 1]; ++r) { }
        ans = max(ans, r - l);
        l = r;
    }

    cout << n - ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if (a<b){
    swap(a, b);
  }
  if (b<c){
    swap(b,c);
  }
  if (a<b){
    swap(a,b);
  }
  cout << c << " " << b << " " << a << endl;
}



Measured memory_bytes: 3088
#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(){

    int N = 1000;
    vector<int> arr(N);
    vector<int> so(0);
    for(int i = 0; i < N; i++){
        arr[i] = 1;
    }
    for(int i = 2; i < sqrt(N); i++){
        if(arr[i]){
            for(int j = 0; i * (j + 2) < N; j++){
                arr[i *(j + 2)] = 0;
            }
        }
    }
    for(int i = 2; i < N; i++){
        if(arr[i]){
            so.push_back(i);
        }
    }

    int n;
    cin >> n;
    vector<int> ya(n+1);
    rep(i, n+1) ya.at(i) = 1;
    for(int i=2; i<=n; i++){
        int k = i;
        rep(j, so.size()){
            while(k%so.at(j) == 0){
                k/=so.at(j);
                ya.at(so.at(j))++;
            }
        }
    }
    ll ans = 1;
    rep(i, n+1){
        ans *= ya.at(i);
        if(ans >= 1000000007) ans %= 1000000007;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function


main :: IO ()
main = do
  n <- read <$> getLine
  ls <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  print $ binSearch 0 n ls

binSearch :: Int -> Int -> VU.Vector Int -> Int
binSearch ng ok !ls | ok - ng <= 1 = ok
binSearch ng ok !ls =
  if isPossibleWith mid ls then
    binSearch ng mid ls
  else
    binSearch mid ok ls
  where
    mid = (ng + ok) `shiftR` 1


isPossibleWith :: Int -> VU.Vector Int -> Bool
isPossibleWith 1 ls = VU.and $ VU.zipWith (<) ls (VU.tail ls)
isPossibleWith numChars ls
  = VU.foldr loop (\_ _ -> True) ls 0 Nil
  where
    loop !reqLen cont !wordLen !charList
      | reqLen > wordLen = cont reqLen charList
      | otherwise = loop1 (cont reqLen)
                    (cutOff charList reqLen) (reqLen - 1)
    loop1 _ !xs !ind | ind < 0 = False
    loop1 cont xs@(Snoc xs' i e) ind = case compare i ind of
      LT -> cont $! Snoc xs ind 1
      EQ | e < numChars - 1 -> cont $! Snoc xs' i (e+1)
         | otherwise        -> loop1 cont xs' (ind-1)
    loop1 cont Nil ind = cont $! Snoc Nil ind 1

data List = Nil | Snoc !List {-# UNPACK #-} !Int {-# UNPACK #-} !Int
 deriving Show


cutOff :: List -> Int -> List
cutOff (Snoc xs i e) till | till <= i = cutOff xs till
cutOff xs !till = xs

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

int main() {
    int n;
    cin>>n;
    int o,t;
    
    int cnt=0;
    int flag=0;
    while(n--){
        cin>>o>>t;
        if(o==t)
        cnt++;
        else
        cnt=0;
        if(cnt>=3)
        {
            cout<<"Yes"<<endl;
            flag=1;
            break;
        }
    }
    if(flag==0)
    cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
 
int main(){
    int n,i;
    while(cin >> n,n){
        //int point[100]={0,};
		int p;
        int min = 1000;
        int max = 0;
		int total = 0;
        for(int i=0;i<n;i++){
            //cin >> point[i];
			cin >> p;
            //if(point[i] > max) max = point[i];
			if(p > max) max = p;
            //if(point[i] < min) min = point[i];
			//total += point[i];
			if(p < min) min = p;
			total += p;
        }
        cout << (total-max-min)/(n-2) << "\n";
    }

}

Measured memory_bytes: 1160
n,m = map(int,input().split())
ps = []
ans = [0,0]
wa = [0]*(n+1)
solved = [0]*(n+1)
for i in range(m):
  p,s = input().split()
  p = int(p)
  if not solved[p]:
    if s=="AC":
      ans[0]+=1
      ans[1]+=wa[p]
      solved[p]=1
    else:
      wa[p]+=1

print(ans[0],ans[1])

Measured memory_bytes: 10380
/*Saurav Paul*/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define endl '\n'
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define boost		          ios_base::sync_with_stdio(0);
#define eb                    emplace_back
#define mp                    make_pair
#define clr(x)                x.clear()
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()

using ll = long long int ;
using namespace std;
///////////////////////

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

////////////////////////
/*
template<typename T>T set_bit(T N,T pos){return N=N | (1<<pos);}
template<typename T>T reset_bit(T N,T pos){return N= N & ~(1<<pos);}
template<typename T> bool check_bit(T N,T pos){return (bool)(N & (1<<pos));}
template<typename T>void bin_print(T N){bitset<25>bit(N);cerr<<bit.to_string()<<"\n";}
template<typename T> void max_self(T &a, T b){
	a=max(a,b);
}
template <typename T > void min_self(T &a, T b){
	a=min(a,b);
}
template <typename T > void add_self(T &a, T b){
	a+=b;
}
*/
////////////////////////

template<typename T> void ara_read(T &v,ll n){
	ll temp;
	for(ll i=0; i< n; i++){
		scanf("%lld",&temp);
		v.emplace_back(temp);
	}
}
template<typename T> void ara_print(T &v){
	for(ll x : v)
		printf("%lld ",x);
	puts("");
}
////////////////////////
const int INF = 1e9 + 99;
using Pair = pair<int,int >;
using vec = vector<int> ;

int main()
{
	long long int n,ans=1;
	cin >> n;
	cout << 3 * (n*n) << endl;
	
    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let (a, b, q) = {
        let ab:Vec<_> = st.trim().split(" ").map(|x| x.parse::<i64>().unwrap()).collect();
        (ab[0], ab[1], ab[2])
    };
    let mut s:Vec<i64> = Vec::new();
    let mut t:Vec<i64> = Vec::new();
    let f:i64 = -100000000001;
    let e:i64 = 100000000001;
    s.push(f);
    t.push(f);
    for _i in 0..a {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        s.push(st.trim().parse::<i64>().unwrap());
    };
    s.push(e);

    for _i in 0..b {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        t.push(st.trim().parse::<i64>().unwrap());
    };
    t.push(e);

    let mut x:Vec<_> = Vec::new();
    for _i in 0..q {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        x.push(st.trim().parse::<i64>().unwrap());
    };

    for i in &x {
        let n = bisec(&mut s, &i);
        let m = bisec(&mut t, &i);
        let mut result:Vec<i64> = Vec::new();
        result.push(max(&s[n], &t[m])-i);
        result.push(i-min(&s[n-1], &t[m-1]));
        result.push(min(&(i-s[n]).abs(), &(i-t[m-1]).abs())+(s[n]-t[m-1]).abs());
        result.push(min(&(i-s[n-1]).abs(), &(i-t[m]).abs())+(s[n-1]-t[m]).abs());
        println!("{}", result.iter().min().unwrap());
    };
}

fn bisec(v:&Vec<i64>, num:&i64) -> usize {
    let mut l:usize = 0;
    let mut r = v.len() as usize;
    let mut m = (l+r)/2 as usize;
    while l < r {
        if num <= &v[m] {
            r = m;
        } else {
            l = m+1;
        };
        m = (l+r)/2 as usize;
    };
    l
}

fn max (a:&i64, b:&i64) -> i64 {
    if a < b {
        *b
    } else {
        *a
    }
}

fn min (a:&i64, b:&i64) -> i64 {
    if a > b {
        *b
    } else {
        *a
    }
}

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

const int INF = 1001001001;

int main(){

    int n;
    cin >> n;
    int ntle=0,nac=0,nre=0,nwa=0;
    rep(i,n){
        string s;
        cin>>s;
        if(s=="AC")nac++;
        if(s=="WA")nwa++;
        if(s=="TLE")ntle++;
        if(s=="RE")nre++;
    }

    cout<<"AC x "<<nac<<endl;
    cout<<"WA x "<<nwa<<endl;
    cout<<"TLE x "<<ntle<<endl;
    cout<<"RE x "<<nre<<endl;
    return 0;
}


Measured memory_bytes: 3624
import math

def Euclid(a, b):
    if a == 0 and b > 0:
        return 0, 1
    r = q = 0
    x = y = 0
    if a >= b:
        r = a % b
        q = a // b
        x1, y1 = Euclid(r, b)
        x = x1
        y = y1 - q * x1
    else:
        r = b % a
        q = b // a
        x1, y1 = Euclid(r, a)
        x = y1 - q * x1
        y = x1
    return x, y

line = input()
a, b = list(map(int, line.split()))
x, y = Euclid(a, b)
if x > y:
    t = math.floor(- (x - y)/(a + b))
    x1 = b * t + x
    y1 = - a * t + y
    if abs(x) + abs(y) >= abs(x1) + abs(y1):
        x, y = x1, y1
print(x, y)


Measured memory_bytes: 5676
#include "bits/stdc++.h"

using namespace std;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

long long lcm(long long x, long long y) {
	return x * y / gcd(x, y);
}

int main() {
	long long A,B;
	cin >> A >>B;
	cout << lcm(A,B)<<  endl;
	
	return 0;
}


Measured memory_bytes: 3632
s = input()
stock_bc = 0
state = 0
ans = 0

for i in range(len(s)):

    if s[-1-i] == "C":
        if state == 1:
            stock_bc = 0
        state = 1

    elif s[-1-i] == "B":
        if state == 0:
            stock_bc = 0
        elif state == 1:
            stock_bc += 1
        state = 0

    elif s[-1-i] == "A":
        if state == 0:
            ans += stock_bc
        else:
            stock_bc = 0
            state = 2

print(ans)

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

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n);
	for (auto& a : h) cin >> a;
	sort(h.begin(), h.end(), greater<>());
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		if (k) --k;
		else ans += h[i];
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];

	int ans = 1;
	int mx = h[0];
	rep(i, n - 1) {
		if (mx <= h[i + 1]) ans++;
		mx = max(mx, h[i + 1]);

	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define lp(i,n) for(int i=0;i<n;i++)
#include<bits/stdc++.h>

using namespace std;
int main() {
	int n, a, b;
	cin >> n;
	if (n == 2) {
		cin >> a >> b;
		cout << a + b << endl;
		return 0;
	}
	cout << "Hello World" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,k,n,max=0;
	cin>>n;
	int a[n][3];
	int dp[n][3];
	for(i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(i=1;i<n;i++)
	{
		for(j=0;j<3;j++)
		{
			max=0;
			for(k=0;k<3;k++)
			{
				if(dp[i-1][k]>max && k!=j)
				{
					max=dp[i-1][k];
				}
			}
			dp[i][j]=a[i][j]+max;
		}
	}
	max=0;
	for(i=0;i<3;i++)
	{
		if(dp[n-1][i]>max)
		{
			max=dp[n-1][i];
		}
	}
	cout << max <<'\n';
}

Measured memory_bytes: 2560
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#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++)
const long long INF =  999999999;

int a,b;

int main(){
  cin>>a>>b;
  if(a>b){
    REP(i,a)cout<<b;
  }else{
    REP(i,b)cout<<a;
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#define int long long

using namespace std;

int S[100100];
int n,q;
int T;

signed main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    cin>>q;
    int L=0;
    int R=n;
    int cnt=0;
    int mid;
    for(int i=0;i<q;i++){
        cin>>T;
        L=0;
        R=n;
        for(int j=0;j<18;j++){
            int mid=(L+R)/2;
            //cout<<mid<<endl;
            if(S[L]==T){
                cnt++;
                //cout<<"succes"<<endl;
                break;
            }
            else if(S[mid]<=T){
                L=mid;
            }
            else if(S[mid]>T){
                R=mid;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1936
import itertools, math

N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

sum = 0

pathes = list(itertools.permutations(range(N), N))

for path in pathes:
    prev_x, prev_y = (x[path[0]], y[path[0]])
    for i in path:
        sum += ((x[i]-prev_x)**2 + (y[i]-prev_y)**2)**0.5
        prev_x, prev_y = (x[i], y[i])

print(sum / math.factorial(N))

Measured memory_bytes: 47212
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define int long long
#define vll vector<long long>
#define pii pair<long long ,long long >
#define vvi vector< vector<long long > >
#define vpii vector<pair<int,int>>
#define pll  pair<long long ,long long >
#define pb  push_back
#define ff  first
#define sec second
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend())
#define m_p make_pair
#define all(x) (x.begin(),x.end())
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD = 1e9 + 7 ;
int size = 10000000;


void solve() {

  int n; cin >> n;
  string s; cin >> s;

  vi r, b, g;
  for ( int i = 0; i < n ; i++ ) {
    if ( s[i] == 'R') r.pb(i);
    else if ( s[i] == 'G') g.pb(i);
    else b.pb(i);
  }
  int ans = 0 ;

  //debug(r, g, b);
  for ( int i = 0; i < (int)r.size() ; i ++ ) {
    for ( int j = 0 ; j < (int)g.size() ; j++) {

      int mn = min({r[i], g[j]});
      int mx = max({r[i], g[j]});

      int v1 = 2 * mn - mx;
      int v2 = 2 * mx - mn;
      double v3 = (double)(mx + mn) / 2;

      if ((int)b.size() > 0) {

        int id = lower_bound(b.begin(), b.end(), v1) - b.begin();
        if (id < n &&  b[id] == v1) ans--;

        id = lower_bound(b.begin(), b.end(), v2) - b.begin();
        if (id < n && b[id] == v2) ans--;

        if (v3 == floor(v3)) {
          id = lower_bound(b.begin(), b.end(), v3) - b.begin();
          if (id < n  && b[id] == v3) ans--;
        }
        ans += (int)b.size();

      }

    }
  }

  cout << ans << endl;

}


int32_t main() {
  fast;
  /*  #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
    #endif */

  int T = 1; //cin>>T;
  while (T--) {
    solve();
  }

  return 0;
}



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


int main(){
  int N,R;
  
  cin>> N >> R;
  
  if(N>=10)
    cout << R << endl;
  else
    cout << R + 100*(10-N) <<endl;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 20000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int d[N][N] = {};
    int d2[N][N] = {};
    rep(i, N) rep(j, N) d[i][j] = d2[i][j] = INF;
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = d2[a][b] = c;
        d[b][a] = d2[b][a] = c;
    }
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int cnt = 0;
    rep(i, N) {
        rep(j, N) {
            if (d[i][j] == INF) continue;
            if (i < j) continue;
            if (d[i][j] == d2[i][j] ) cnt++;
        }
    }
    cout << M - cnt << endl;

    return 0;
}


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

int N, W;
long long value[110], weight[110];
long long int dp[110][100010];

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];
  for (int w = 0; w <= W; w++) dp[0][w] = 0;
  
  for (int i = 0; i < N; i++) {
    for (int w = 0; w <= W; w++) {
      if (w >= weight[i]) dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
      else dp[i + 1][w] = dp[i][w];
    }
  }
  
  cout << dp[N][W] << endl;
  
  return 0;
}

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

int main() {
	int n, k;
	scanf("%d%d", &k, &n);
	if (k == 1) {
		for (int i = 0; i < (n + 1) / 2; i++)
			printf("1 ");
	} else if (k % 2) {
		int64_t num = 0, cur = 1;
		int i = 0;
		for (; i < n && num < 100000000LL; i++)
			num += cur *= k;
		if (i == n) {
			int64_t t = (num - 1) / 2;
			std::vector<int> res;
			for (int i = 0; i < n; i++) {
				if (i) {
					if (!t) break;
					t--, num--;
				}
			  num /= k;
				res.push_back(t / num);
				t %= num;
			}
			for (auto j : res) printf("%d ", j + 1);
		} else {
			int shift = 0;
			std::vector<int> res;
			for (int j = 0; j < n - i; j++) {
        if (j && (n - j) % 2) shift++;
				res.push_back((k + 1) / 2);
			}
			num++;
			int64_t t = (num - 1) / 2 - shift;
			assert(t >= 0);
      for (int j = n - i; j < n && t; j++) {
				t--, num--;
				num /= k;
				res.push_back(t / num + 1);
				t %= num;
			}
      for (auto j : res) printf("%d ", j);

		}
	} else {
		printf("%d", (k + 1) / 2);
		for (int i = 0; i + 1 < n; i++)
			printf(" %d", k);
	}
  return 0;
}


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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
const int INF = (int)1e9 + 9;
using vint = vector<int>;

int main() {
    int N, K;
    cin >> N >> K;
    vint h(N);
    REP(i, N) cin >> h[i];
    vint dp(N, INF);
    dp[0] = 0;
    REP(i, N) {
        REP1(j, K) {
            if (i + j < N)
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[N - 1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <map> 
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	map<int, int> A;
	for (int i = 0; i < N; i++) {
		int Ai;
		cin >> Ai;
		A[Ai]++;
	}

	long long l = -1, s = -1;
	for (pair<int, int> p : A) {
		int a = p.first, cnt = p.second;
		if (cnt < 2) continue;
		if (cnt >= 2 && l < a) {
			s = l;
			l = a;
			cnt -= 2;
		}
		if (cnt >= 2 && s < a) {
			s = a;
		}
	}

	if (l == -1 || s == -1) cout << "0" << endl;
	else cout << l * s << endl;

	return 0;
}

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

using i64 = long long;
using P   = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

const string YES = "Yes";
const string NO  = "No";

void solve(long long D, long long T, long long S) {
    if(T * S >= D)
        cout << YES << endl;
    else
        cout << NO << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    long long D;
    scanf("%lld", &D);
    long long T;
    scanf("%lld", &T);
    long long S;
    scanf("%lld", &S);
    solve(D, T, S);
    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

string a,b,c;

int main(){
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 1
#define INF (1LL << 50)

int main(){

	lli N,M;
	cin>>N>>M;

	const lli NMAX = 1000;
	const lli MMAX = 2000;
	lli a[MMAX],b[MMAX];
	lli c[MMAX];

	REP(i,M){
		cin>>a[i]>>b[i]>>c[i];
		c[i] = -c[i];
	}

	lli dist[NMAX];

	for(lli i=0;i<N;i++){
		dist[i]=INF;
	}

	dist[0] = 0;

	for(lli loop = 0;loop<N-1;loop++){
		for(lli i=0;i<M;i++){
			if(dist[a[i]-1]==INF)continue;

			if(dist[b[i]-1] > dist[a[i]-1]+c[i]){
				dist[b[i]-1] = dist[a[i]-1]+c[i];
			}
		}
	}

	lli ans = dist[N-1];

	bool negative[NMAX];

	for(lli i=0;i<N;i++)negative[i]=false;

	for(lli loop = 0;loop<N;loop++){
		for(lli i=0;i<M;i++){
			if(dist[a[i]-1]==INF)continue;

			if(dist[b[i]-1] > dist[a[i]-1]+c[i]){
				dist[b[i]-1] = dist[a[i]-1]+c[i];
				negative[b[i]-1] = true;
			}
			if(negative[a[i]-1]==true)negative[b[i]-1]=true;
		}
	}

	if(negative[N-1])cout<<"inf"<<endl;
	else cout<<-ans<<endl;

	return 0;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int a, b; rd(a, b);
  for(int c=1; c<=3; c++){
    if((a*b*c)&1){
      writeln("Yes");
      return;
    }
  }

  writeln("No");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int[] v = new int[N];
			int sum = 0;
			for (int i = 0; i < N; ++i) {
				v[i] = sc.nextInt();
				sum += v[i];
			}
			int ans = sum;
			for (int i = 1; i < (1 << N); ++i) {
				int a = 0;
				for (int j = 0; j < N; ++j) {
					if ((i & (1 << j)) != 0) {
						a += v[j];
					}
				}
				ans = Math.min(ans, Math.abs(a - (sum - a)));
			}
			System.out.println(ans);
		}
	}
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, K; cin >> N >> K;
    int A[N];
    int S; cin >> S;
    if(S == 1000000000){
        rep(i, K) A[i] = S;
        for(int i = K; i < N; i++){
            A[i] = 1;
        }
    }
    else{
        rep(i, K) A[i] = S;
        for(int i = K; i < N; i++){
            A[i] = 1000000000;
        }
    }
    rep(i, N) cout << A[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int X = scan.nextInt();
			int N = scan.nextInt();
			int[]p = new int[N];
			Set<Integer>set = new TreeSet<Integer>();
			for(int i = 0;i<N;i++) {
				p[i] = scan.nextInt();
				set.add(p[i]);
			}
			
			if(N==0) {
				System.out.println(X);
				System.exit(0);
			}
			
			int i =0;
			int ans = 0;
			while(true) {
				
				int S = X-i;
				if(!set.contains(S)) {//含まれてないなら答え
					ans = S;
					break;
				
					
				}
				
				int D = X+i;
				if(!set.contains(D)) {//含まれてないなら答え
					ans=D;
					break;
				}
				
				i++;
				

			}
			
			System.out.println(ans);
			
			
			
			
			
			
			
			
			
		}
		
		
	}
		

	
}


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

int main()
{
    vector<int> ns(4);
    for(int i=0; i<4; i++)
    {
        cin >> ns.at(i);
    }

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

    if(ns.at(0) == 1 && ns.at(1) == 4 && ns.at(2) == 7 && ns.at(3) == 9)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    

    return 0;
}


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

int main () {
int d,n;
int ans;
cin >> d >> n;
if(n != 100){
if(d == 0){ans = n;}
else if(d == 1){ans = n * 100;}
else{ans = n * 10000;}
}else{
if(d == 0){ans = n+1;}
else if(d == 1){ans = n * 100+100;}
else{ans = n * 10000+10000;}
}
cout << ans <<endl;
return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<=e;i++)
#define rforse(i,s,e) for(int i=e;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	int n, m, q;
	cin>>n>>m>>q;
	vi qa(q), qb(q), qc(q), qd(q);
	forn(i, q) cin>>qa[i]>>qb[i]>>qc[i]>>qd[i];
	forn(i, q){ qa[i]--; qb[i]--;}
	vi a(10);
	int ans = 0;
	forse(i0,1, m) forse(i1, i0, m) forse(i2, i1, m) forse(i3, i2, m) forse(i4, i3, m)
	forse(i5, i4, m) forse(i6, i5, m) forse(i7, i6, m) forse(i8, i7, m) forse(i9, i8, m){
		a[0] = i0; a[1] = i1; a[2] = i2; a[3] = i3;
		a[4] = i4; a[5] = i5; a[6] = i6; 
		a[7] = i7; a[8] = i8; a[9] = i9;
		int sum = 0;
		forn(i, q) if(a[qb[i]]-a[qa[i]]==qc[i]) sum += qd[i];
		ans = max(ans, sum);
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

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

int main(){
  int a, b, c; cin >> a >> b >> c;
  int ans;
  int maximum; maximum = max(max(a, b), c);
  ans = maximum*9 + a + b + c;
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

ll mod=1e9+7;

ll dp[2010][2010];

int main(){
  ll n,m;
  cin >> n >> m;
  ll a[n],b[m];
  for(ll i=0;i<n;i++) cin >> a[i];
  for(ll i=0;i<m;i++) cin >> b[i];
  for(ll i=0;i<=m;i++) dp[0][i]=1;
  for(ll i=0;i<=n;i++) dp[i][0]=1;
  for(ll i=1;i<=n;i++){
    ll count=1;
    for(ll j=1;j<=m;j++){
      ll x=a[i-1],y=b[j-1];
      dp[i][j]=dp[i][j-1];
      if(x==y) dp[i][j]=(dp[i][j]+count)%mod;
      count=(count+dp[i-1][j]-dp[i-1][j-1]+mod)%mod;
      dp[i][j]=(dp[i][j]+dp[i-1][j]-dp[i-1][j-1]+mod)%mod;
    }
  }
  for(ll i=0;i<=n;i++){
    for(ll j=0;j<=m;j++){
      //cout << dp[i][j] << " ";
    }
    //cout << endl;
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;

long long int intpow(long long int x,long long int n){
    long long int ans=1;
    for(int i=0;i<n;i++){
        ans*=x;
    }
    return ans;
}

int main(){
    ll n,a,d=1;
    cin>>n;
    vector<int> vec;
    vector<char> vec2;
    for(int i=0;d<=n;i++){
        vec.push_back((n/d)%26);
        d*=26;
    }
    vec_debug(vec);
    for(int i=0;i<vec.size();i++){
        if(vec[i]<=0){
            if(i+1<vec.size()){
                vec[i+1]--;
                vec[i]+=26;
            }else{
                break;
            }
        }
        vec[i]--;
        vec2.push_back(vec[i]+'a');
    }
    reverse(all(vec2));
    rep(i,vec2.size()){
        cout<<vec2[i];
    }
    cout<<endl;
}

Measured memory_bytes: 3632