akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
#include <set>
using namespace std;

struct RollingHash {
    vector<unsigned long long> hash[2], power[2];
    const unsigned int seed = 10007;
    const unsigned int mod[2]  = {999999937, 1000000007};

    RollingHash(const string &s) {
        int n = (int)s.size();
        for(int m = 0; m < 2; ++m) {
            hash[m].assign( n + 1, 0);
            power[m].assign(n + 1, 1);

            for(int i = 0; i < n; ++i) {
                hash[m][i+1]  = (hash[m][i] * seed + s[i]) % mod[m];
                power[m][i+1] = power[m][i] * seed % mod[m];
            }
        }
    }

    // [l, r)
    unsigned long long get_hash(int l, int r, int m = 0) {
        unsigned long long ret = (hash[m][r] - hash[m][l] * power[m][r-l] % mod[m] + mod[m]) % mod[m];
        return ret;
    }
};

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

    int n,q; cin >> n >> q;
    string s, t; cin >> s;

    RollingHash rh(s);
    int l = 0, r = 0;
    set<pair<unsigned long long, unsigned long long>> ans;
    while(q--) {
        cin >> t;
        if(t == "R++") ++r;
        if(t == "R--") --r;
        if(t == "L++") ++l;
        if(t == "L--") --l;
        ans.insert(make_pair(rh.get_hash(l, r+1, 0),rh.get_hash(l, r+1, 1)));
    }

    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 31284
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b<c){
        put("No");
    }else{
        put("Yes");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using pii = pair<int, int>;
using ll = long long int;
using ld = long double;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }

int N, W, t, s;
vector<int> v;
vector<int> w;
vector<vector<int>> dp;

int knapsack(int i, int u) {
    if (i >= N) return 0;
    if (u < w[i]) return knapsack(i + 1, u);
    if (dp[i][u] >= 0) return dp[i][u];
    return dp[i][u] = max(knapsack(i + 1, u), knapsack(i + 1, u - w[i]) + v[i]);
}

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) {
        cin >> t >> s;
        v.push_back(t);
        w.push_back(s);
    }
    dp = vector<vector<int>>(N + 1, vector<int>(W + 1, -1));
    int ans = knapsack(0, W);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6720
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int sum = 0;
		while(sum < N) {
			sum += 1000;
		}
		System.out.println(sum - N);
	}
}


Measured memory_bytes: 35856
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	ap := strings.Fields(nextLine())
	a, _ := strconv.Atoi(ap[0])
	p, _ := strconv.Atoi(ap[1])
	p += a * 3
	fmt.Println(p / 2)
}


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

int main(){
  int n;cin>>n;
  double rans=0;
  int a;
  for(int i=0;i<n;i++){
    cin>>a;
    rans+=1.0/a;
  }
  printf("%.10lf\n",1.0/rans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[200000];
int l[200000];
int r[200000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	l[0] = a[0];
	for (i = 1; i < n; i++) {
		l[i] = max(l[i - 1], a[i]);
	}
	
	r[n - 1] = a[n - 1];
	for (i = n - 2; i >= 0; i--) {
		r[i] = max(r[i + 1], a[i]);
	}
	
	for (i = 0; i < n; i++) {
		if (i == 0) cout << r[1] << endl;
		else if (i == n - 1) cout << l[n - 2] << endl;
		else cout << max(l[i - 1], r[i + 1]) << endl;
	}
	return 0;
}

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

const int M = 1e6 + 100;
int l[M], r[M];
int id[M], tp[M];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		int x = 0, y = 0;
		for (char c : s) {
			if (c == '(') ++x;
			else if (x) --x;
			else ++y;
		}
		l[i] = x, r[i] = y, id[i] = i;
		if (y == 0) tp[i] = 1;
		else if (x == 0) tp[i] = 4;
		else if (x >= y) tp[i] = 2;
		else tp[i] = 3;
	}
	sort(id, id + n, [&] (int a, int b) {
		if (tp[a] != tp[b]) return tp[a] < tp[b];
		if (tp[a] == 2) {
			if (r[a] != r[b]) return r[a] < r[b];
			else return l[a] > l[b];
		}
		if (tp[a] == 3) return l[a] > l[b];
		return false;
	});
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum -= r[id[i]];
		if (sum < 0) break;
		sum += l[id[i]];
	}
	cout << (sum == 0 ? "Yes" : "No");
}

Measured memory_bytes: 19124
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a ,b , c;
    cin >> a >> b >>c;
    if(a == b && c != a)
        cout << "Yes";
    else if(a == c && b != a)
        cout << "Yes";
    else if(b == c && c != a)
        cout <<"Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

a_ = [[0]*3 for _ in range(3)]
for i in b:
    for j in range(3):
        for k in range(3):
            if a[j][k] == i:
                a_[j][k] = 1
                
count = 0
for i in range(3):
    count += (a_[i][0]+a_[i][1]+a_[i][2])//3
    count += (a_[0][i]+a_[1][i]+a_[2][i])//3
    
count += (a_[0][0]+a_[1][1]+a_[2][2])//3
count += (a_[0][2]+a_[1][1]+a_[2][0])//3

if count > 0:
    print('Yes')
else:
    print('No')

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

int main(){
  
  int n,sum=0;
  cin >> n;
  for(int i=0; i<n; i++){
    int x,y;
    cin >> x >> y;
    sum+=(y-x+1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3560
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]
s = [0]*(2*10**5+2)
s[3] = 1
for i in range(3, 10**5):
    for j in range(2, int((2*i)**0.5)+2):
        if (i > j and i % j == 0) or (2*i-1) % j == 0:
                b = 0
                break
    else:
        b = 1
    s[2*i-1] = b
S = [0]
for i in range(1, 10**5+1):
    c = S[i-1] + s[i]
    S.append(c)
for i in range(q):
    print(S[a[i][1]] - S[a[i][0]-1])

Measured memory_bytes: 33188
N, T, *V = map(int, open(0).read().split())
cs = V[0::2]
ts = V[1::2]
ans = 1001

for i in range(N):
  if(ts[i] > T):
    continue
  if(cs[i] < ans):
    ans = cs[i]

if(ans == 1001):
  print("TLE")
else:
  print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	string S;
	int l;
	ll res=0;
	cin>>S;
	l=S.length();
	for(int i=0,e=0;i<pow(2,l-1);i++)
	{
		int s=0;
		for(int j=0;j<l-1;j++)
		{
			if((i>>j)&1)
			{
				res+=atol(S.substr(s,j-s+1).c_str());
				s=j+1;
			}
		}
		res+=atol(S.substr(s,l-s).c_str());
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 384
import java.util.*; 
import java.lang.*; 

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		String N = scan.next();

		for (int i = 0; i <= 2; i++){
			char K = N.charAt(i);
			if(K=='7'){
				System.out.println("Yes");
				System.exit(0);
			}
		}
		
		System.out.println("No");
	}
}

Measured memory_bytes: 35720
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

const int MAX = 1e5 + 1;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();
    s64 N, K;
    cin >> N >> K;

    if (K == 1)
    {
        cout << "0\n";
        return 0;
    }

    vs64 A(N);
    rep (i, N) cin >> A[i];
    sort(A.begin(), A.end());

    vs64 S(N + 1);
    S[0] = 0;
    for (int i = 0; i < N; ++i)
    {
        S[i + 1] = S[i] + A[i];
        while (S[i + 1] < 0) S[i + 1] += MOD;
        S[i + 1] %= MOD;
    }

    s64 ans = 0;
    for (int i = 1; i <= N - K + 1; ++i)
    {
        s64 temp = (S[N] - S[i + K - 2]) - (S[N - K + 2 - i]);
        while (temp < 0) temp += MOD;
        temp %= MOD;
        temp *= COM(K - 3 + i, K - 2);
        temp %= MOD;
        ans += temp;
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}



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

int main(){
  int count=0;
  string data,data1,data2;
  cin>>data;
  if(data.size()%2==0){
    count+=2;
    data1=data.substr(0,data.size()/2-1);
    data2=data.substr(data.size()/2-1,data.size()/2-1);
  }
  else if(data.size()%2!=0){
    count+=1;
    data1=data.substr(0,(int)data.size()/2);
    data2=data.substr((int)data.size()/2,(int)data.size()/2);
  }

  while(data1!=data2){
 
    count+=2;
    data1=data.substr(0,(int)(data.size()-count)/2);
    data2=data.substr((int)(data.size()-count)/2,(int)(data.size()-count)/2);

  }

  cout<<data1.size()*2<<endl;
}



Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]

d = dict()

for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

ans = 0
even = 0
for i in d.values():
    if i % 2 == 0:
        even += 1
    ans += 1

if even % 2 == 1:
    ans -= 1

print(ans)


Measured memory_bytes: 17312
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int a,b;cin >> a >> b;
    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){

int n,i,ara[100];
scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&ara[i]);
}
for(i=n-1;i>0;i--)
    {printf("%d ",ara[i]);}
printf("%d\n",ara[0]);
return 0;
}



Measured memory_bytes: 2116
import statistics
N = int(input())
A = [int(x) for x in input().split(' ')]
def score(C, b):
    s = 0
    for i, Ci in enumerate(C):
        s += abs(Ci - b)
    return int(s)

C = [Ai - (i+1) for i, Ai in enumerate(A)]
b = statistics.median(C)
b1 = int(b)
b2 = int(b) + 1
s1 = score(C, b1)
s2 = score(C, b2)
print(min(s1, s2))

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

int n, k;
int cost[5000], r[5000];
bool dp[5000][5010];

vector<vector<int> > e;

int main(){
	
	cin >> n >> k;
	e.resize(n);
	
	for(int i = 0; i < n; i++) cin >> cost[i] >> r[i];
	for(int i = 0; i < k; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	
	priority_queue<pair<int, pair<int, int> > > q;
	
	q.push(make_pair(0, make_pair(0, 0)));
	
	while(!q.empty()){
		
		int co = q.top().first;
		int re = q.top().second.first;
		int cu = q.top().second.second;
		q.pop();
		
		//cerr<<"co: "<<co<<" re: "<<re<<" cu: "<<cu<<endl;
		
		if(dp[cu][re]) continue;
		dp[cu][re] = 1;
		
		if(cu == n - 1){
			cout << -co << endl;
			return 0;
		}
		
		if(!dp[cu][r[cu]]) q.push(make_pair(co - cost[cu], make_pair(r[cu], cu)));
		
		if(--re >= 0) for(int i = 0; i < e[cu].size(); i++){
			
			if(!dp[e[cu][i]][re])
				q.push(make_pair(co, make_pair(re, e[cu][i])));
		}
	}
	
	return 0;
}

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

int main(void) {
    int N;
    int M;
    cin >> N;
    int T[N];
    for(int i=0;i<N;i++) cin >> T[i];
    cin >> M;
    int P[M], X[M];
    for(int i=0;i<M;i++) {
        cin >> P[i];
        cin >> X[i];
    }

    for (int i=0;i<M;i++) {
        int total=0;
        for (int j=0;j<N;j++) {
            if (j+1 == P[i]) {
                total += X[i];
            } else {
                total += T[j];
            }
        }
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from collections import defaultdict

N = int(input())
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

B = []
D = defaultdict(lambda: 0)

for i in range(N):
	B.append([i,A[i]])
	
	k = i - A[i]
	D[k] += 1

ans=0
for i in range(N):
	k = i + A[i]
	ans += D[k]


print(ans)


Measured memory_bytes: 83804
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 1000000009
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll


signed main(void){
    int N;
    int a[114514];
    int sum=0;
    cin >> N;
    REP(i,N){cin >> a[i];}
    sort(a,a+N);
    REP(i,N){
        if(i==0)continue;
        if(a[i]==a[i-1])sum++;
    }
    cout << N - sum - (sum%2==1) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=1000000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 1000000007
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
    #define N 1000000

    int fac[N+100],invfac[N+100];

    int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
    int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
    int mul(int x,int y) {return 1ll*x*y%maxd;}
    ll qpow(ll x,int y)
    {
        ll ans=1;
        while (y)
        {
            if (y&1) ans=mul(ans,x);
            x=mul(x,x);y>>=1;
        }
        return ans;
    }
    int getinv(int x) {return qpow(x,maxd-2);}

    int C(int n,int m)
    {
        if ((n<m) || (n<0) || (m<0)) return 0;
        return mul(mul(fac[n],invfac[m]),invfac[n-m]);
    }

    void math_init()
    {
        fac[0]=invfac[0]=1;
        rep(i,1,N) fac[i]=mul(fac[i-1],i);
        invfac[N]=getinv(fac[N]);
        per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
    }
    #undef N
}
using namespace My_Math;

int n,f[N],g[N];

int main()
{
    n=read();
    math_init();
    rep(i,(n+1)>>1,n-1) f[i]=mul(C(i-1,n-i-1),mul(fac[i],fac[n-1-i]));
    int ans=0;
    rep(i,1,n-1) g[i]=dec(f[i],f[i-1]);
    rep(i,1,n-1) ans=add(ans,mul(i,g[i]));
    printf("%d",ans);
    return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n, d;
int a[N];

int main() {

	FAST;

	cin >> n >> d;
	int k = n / (2 * d + 1);
	if (n % (2 * d + 1)) k ++;
	cout << k << '\n';
	return 0;
}

Measured memory_bytes: 256
module AOJ_Volume0105;

import std.stdio,std.string,std.conv,std.array;

int main()
{
	string f[101];
	string[string] m;
	string s;
	string res[];

	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(" ");
		m[_s[0]] ~= _s[1];
		m[_s[0]] ~= " ";

		bool flag = true;
		foreach(j;0..res.length)
		{
			if(res[j] == _s[0]) flag = false;
		}

		if(flag) res ~= _s[0];
	}
	res.sort;

	foreach(i;0..res.length)
	{
		res[i].writeln;
		m[res[i]] = m[res[i]][0..$-1];
		string[] temp = m[res[i]].split(" ");
		int a[];
		foreach(j;0..temp.length)
		{
			a ~= temp[j].to!int;
		}

		a.sort;
		foreach(j;0..a.length)
		{
			if(j == a.length-1)
			{
				a[j].writeln;
			}
			else
			{
				write(a[j]," ");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1084
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	string X, Y;
	cin >> X >> Y;
	if (X < Y) {
		cout << "<" << endl;
	}
	else if (X > Y) {
		cout << ">" << endl;
	}
	else {
		cout << "=" << endl;
	}
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	string n; cin >> n;
	char t = n[0];
	for (int i = 1; i < 4; i++) {
		if (n[i] == t) {
			cout << "Bad";
			return 0;
		}
		t = n[i];
	}
	cout << "Good";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    a, b, c, d, e, k = map(int, read().split())

    if e - a > k:
        print(':(')
    else:
        print('Yay!')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9072
import java.util.*;
     
    public class Main {
     
        static List<ban> bans;
     
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int C = scan.nextInt();
            bans = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                bans.add(new ban(scan.nextInt() * 2,scan.nextInt() * 2,scan.nextInt()));
            }
            bans.sort(Comparator.comparingInt(x -> x.s));
     
            for (int i = 1; i <= C; i++) {
                boolean success = func(i);
                if (success) {
                    System.out.println(i);
                    return;
                }
            }
        }
     
        private static boolean func(int num) {
            List<tv> tvs = new ArrayList<>();
            for (int i = 0; i < num; i++) {
                tvs.add(new tv(-1, -1));
            }
            for (int i = 0; i < bans.size(); i++) {
                int now = bans.get(i).s;
                int can = bans.get(i).c;
                Optional<tv> tmp = tvs.stream().filter(x -> x.c == -1 || (x.c == can && x.t <= now) || x.t <= now - 1).sorted(Comparator.comparingInt(x -> -x.t)).findFirst();
                if(tmp.isPresent()) {
                    tv temp = tmp.get();
                    temp.t = bans.get(i).t;
                    temp.c = can;
                }
                else {
                    return false;
                }
            }
            return true;
        }
     
        static class tv{
            int t;
            int c;
            public tv(int t, int c) {
                this.t = t;
                this.c = c;
            }
        }
     
        static class ban{
            int s;
            int t;
            int c;
            ban(int s, int t, int c) {
                this.s = s;
                this.t = t;
                this.c = c;
            }
        }
    }

Measured memory_bytes: 121008
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

typedef std::stack<int> IntStack;
typedef std::queue<int> IntQueue;
 
using namespace std;
  
int main(){
  string S,T,U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  
  //int ans = 0;
  if(S == U){
    A -= 1;
  }
  if(T == U){
    B -= 1;
  }
  
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  string A, B;
  cin >> A >> B;
  if (SZ(A) > SZ(B)) {
    cout << "GREATER" << endl;
  } else if (SZ(A) < SZ(B)) {
    cout << "LESS" << endl;
  } else {
    REP(i, A.size()) {
      if (A[i] > B[i]) {
        cout << "GREATER" << endl;
      } else if (A[i] < B[i]) {
        cout << "LESS" << endl;
      } else {
        continue;
      }
      return 0;
    }
    cout << "EQUAL" << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   string s;
   cin >> s;
   int n = s.length();
   int ans = 0;
   for(int i = 0 ; i < n ; i++){
      if(s[i] == '?')
         s[i] = 'D';
   }
   cout << s;
   return 0;
}


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

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

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int s;
	cin >> s;
	vb B(2000000);
	int pre = s;
	int num = 1;
	B[pre] = true;
	while (true) {
		num++;
		if (pre % 2 == 1) {
			pre = pre * 3 + 1;
		}
		else {
			pre = pre / 2;
		}
		if (B[pre]) {
			cout << num << endl;
			return 0;
		}
		B[pre] = true;
	}

	PAU;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
bool f[200009];

int main(){
  int n,m;
  int a[200009],b[200009];
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    if(b[i]==n){
      f[a[i]]=true;
    }
  }
  for(int i=0;i<m;i++){
    if(a[i]==1&&f[b[i]]==true){
      cout<<"POSSIBLE"<<endl;
      return(0);
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  return(0);
}


Measured memory_bytes: 2048
using namespace std;
#include<string>
#include<cmath>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9;
#include<iterator>




void solve() {
	ll n, k; cin >> n >> k;
	ll a[n];
	fr(i, 0, n) {
		cin >> a[i];
		if (i >= k) {
			//score = score*A[i]/A[i-K];
			if (a[i] > a[i - k]) printf("Yes\n");
			else printf("No\n");
		}
		//fr(i, 1, n - k + 1) {if (p[i] > p[i - 1])cout << "Yes\n"; else cout << "No\n";}
	}
}



int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif

	ll t, h = 1;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		//cout << "Case #" << h << ":\n";
		solve();
		//h++;
		//cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 5212
#include <iostream>
#define    N    1001
using namespace std;

void insertionSort(int *A, int n){
	for(int i=0;i<n;i++){
		int v = A[i];
		int j = i-1;
		while((j >= 0) && (A[j] > v)){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		
	for(int k=0;k<n;k++){
		if(k!=0) cout<<" ";
		cout<<A[k];
	}
	cout<<endl;

	}
}

int main(){
	int n, A[N];

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

	insertionSort(A, n);
	
	return 0;
}

Measured memory_bytes: 1164
import collections
n = int(input())
a = [int(i) for i in input().split()]

c = collections.Counter(a)
key = list(c.keys())
if (c[0] == n or (len(key)==2 and c[0] == n/3) or (len(key)==3 and (key[0] ^ key[1] ^ key[2] == 0) and (c[key[0]] == c[key[1]] == c[key[2]]))):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14468
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    int sn = s.size(), tn = t.size();
    bool state = true;
    repi(i, min(sn, tn), 0)
    {
        if (s[i] < t[i])
        {
            cout << "Yes" << endl;
            return 0;
        }else if(s[i] > t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(sn < tn){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(void) {
    string S;
    int maxcnt = 0;
    int cnt = 0;
    cin >> S;

    for(int i=0;i<S.size();i++) {
        switch(S[i]) {
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                cnt++;
                if(maxcnt < cnt) {
                    maxcnt = cnt;
                }
                break;
            default:
                cnt = 0;
        }
    }

    cout << maxcnt << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
N,K = map(int,input().split())
D = list(map(int,input().split()))

#使用可能数字の取り出し
Num1 = []
for i in range(10):
  if(i in D): continue
  else: Num1.append(i)
 
#組み合わせ
Comb = []
n = len(str(N))
for i in range(n+1):
  Comb.append(Num1)
Comb = list(itertools.product(*Comb))

ans = -1
for i in range(len(Comb)):
  tmp = Comb[i]
  tmp_num = ''
  for j in range(n): tmp_num += str(tmp[j])
  tmp_num = int(tmp_num)
  if(N <= tmp_num):
    ans = tmp_num
    break
    
if(ans == -1):
  for i in range(len(Comb)):
   tmp = Comb[i]
   tmp_num = ''
   for j in range(n+1): tmp_num += str(tmp[j])
   tmp_num = int(tmp_num)
   if(N <= tmp_num):
     ans = tmp_num
     break
print(ans)

Measured memory_bytes: 8736
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H')
	{
		if(b=='H')
		{
			cout<<"H"<<endl;
			return 0;
		}
		else
		{
			cout<<"D"<<endl;
			return 0;
		}
	}
	else
	{
		if(b=='H')
		{
			cout<<"D"<<endl;
			return 0;
		}
		if(b=='D')
		{
			cout<<"H"<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> prime(N+1);
    for (int i = 1; i <= N; i++){
        int tmp = i;
        for(int j = 2; tmp != 1;j++){
            while(tmp % j == 0){
                prime[j]++;
                tmp /= j;
            }
        }
    }
    ll answer = 1;
    REP(i,N+1){
        answer = modu(answer * (prime[i] + 1));
    }
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=500009;
const ll MX=999999999999;
ll a[N];
bitset<4000009> dp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll mn=MX; ll ans;
    ll n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
    {
		cin>>a[i];
		sum+=a[i];
	}
	dp[0]=1;
	for(int i=1;i<=n;i++)
    {
		dp=dp|(dp<<a[i]);
    }
	for(int i=4000000;i>=sum/2;i--)
	{
		if(dp[i])
		{
			if(abs(sum-2*i)<mn)mn=abs(sum-2*i),ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2176
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s[] = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        int m = sc.nextInt();
        String t[] = new String[m];
        for (int i = 0; i < m; i++) {
            t[i] = sc.next();
        }
        int yen[] = new int[n];
        for (int i = 0; i < n; i++) {
            String moji = s[i];
            for (int j = 0; j < n; j++) {
                if (s[j].equals(moji)) {
                    yen[i]++;
                }
            }
            for (int j = 0; j < m; j++) {
                if (t[j].equals(moji)) {
                    yen[i]--;
                }
            }
        }
        Arrays.sort(yen);
        System.out.println(Math.max(yen[n - 1], 0));
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

using namespace std;

int main(){
   int m,f,r;
   char grade;
   while(true){
       scanf("%d %d %d",&m,&f,&r);
       if(m == -1 && f == -1 && r == -1) break;
       if(m == -1 || f == -1){
           grade = 'F';
       }else if(m+f >= 80){
           grade = 'A';
       }else if(m+f >= 65){
           grade = 'B';
       }else if(m+f >= 50){
           grade = 'C';
       }else if(m+f >= 30){
           grade = (r >= 50)? 'C':'D';
       }else{
           grade = 'F';
       }
       printf("%c\n",grade);
   }
}


Measured memory_bytes: 2612
K = int(input())
S = input()
# N, M = map(int, input().split())
# X = [[] for _ in range(N)]
# for i in range(N):
#     X[i] = list(map(int, input().split()))

if len(S) <= K:
    print(S)
else:
    print(S[:K]+'...')

Measured memory_bytes: 9164
def tasu(x):
    return x / 2 * (x + 1)

def kitaiti(n , k , p):

    ans = 0
    count = 0
    kitai = [0]*n
    kitaisum = [0]*n
    mod = 10**9+7

    for i in range(n):
        kitai[i] = tasu(p[i]) / p[i]

    for i in range(n):
        if i == 0:
            kitaisum[i] += kitai[i]
        else:
            kitaisum[i] += kitai[i] + kitaisum[i-1]

    for i in range(n - k + 1):

        ans = max(ans , (kitaisum[i + k - 1] - kitaisum[i-1]) if i != 0 else kitaisum[i + k - 1])

    return ans

def main():
    n , k = map(int , input().split())
    p = list(map(int,input().split()))
    print(kitaiti(n , k , p))

if __name__ == '__main__':
    main()

Measured memory_bytes: 25596
import java.util.Scanner;

public interface Main {
	static int a = 1;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i, x, y, a;
		for(i=0; i<3000; i++) {
		x = sc.nextInt();
		y = sc.nextInt();
		if(x == 0 && y == 0)	break;
		if(x > y) {
			a = x;
			x = y;
			y = a;
		}
		System.out.printf("%d %d\n", x,y);
		}
		
	}
}


Measured memory_bytes: 39760
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>

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

typedef long long ll;

using namespace std;

int main() {

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

    vector<int> cnt(n-1,0);

    FOR(i, 1, n){
        string l = s.substr(0,i);
        string r = s.substr(i,n-i);
        for(char c='a';c<='z';c++){
            if ((l.find(c) != string::npos)&&(r.find(c) != string::npos)) {
                cnt[i-1]++;
            }
        }
    }

    int max = *max_element(cnt.begin(),cnt.end());

    cout << max << endl;

    return 0;
}


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


int main() {
  ll n,m;
  cin>>n>>m;
  vector<ll> a(m);
  vector<ll> b(m);
  vector<ll> c(m);
  rep(i,m){
    ll c1;
    cin>>a[i];
    a[i]--;
    cin>>b[i];
    b[i]--;
    cin>>c1;
    c[i]=-c1;
  }
  vector<ll> d(n);
  rep(i,n)d[i]=INF;
  d[0]=0;
  rep(i,n){
    rep(j,m){
    if (d[a[j]]==INF)continue;
    d[b[j]]=min(d[b[j]], d[a[j]]+c[j]);
    }
  }
  vector<ll> neg(n,0);
  rep(i,n){
    rep(j,m){
      if (d[a[j]]==INF)continue;
      if (d[b[j]]>d[a[j]]+c[j]){
        d[b[j]]=d[a[j]]+c[j];
        neg[b[j]]=-1;
      }
      if (neg[a[j]]==-1) neg[b[j]]=-1;
      }
    }

  if (neg[n-1]==-1)cout<<"inf";
  else cout<<-d[n-1];




}


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

int main(void) {

  int N, D, count=0;
  cin >> N >> D;
  int X[N][D];

  for (int  i=0; i < N; i++) {
    for (int j=0; j < D; j++) {
      cin >> X[i][j];
    }       
  }

  for (int i=0; i < N; i++) {
    for (int j=i+1; j < N; j++) {
      double distance = 0;
      for (int k=0; k < D; k++) {
        distance += pow((X[i][k] - X[j][k]),2);
      }
      distance = sqrt(distance);
      if (distance - floor(distance) == 0) {
        count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

using Graph = vector<vector<ll>>;

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

#define MAX_N 2010

const long long INF = 1LL << 60;

//境界値に注意！！！
int main() {
    ll h,w;
    cin >> h >> w;
    vector<vector<ll>> x(h,vector<ll>(w));
    for (ll i=0;i<h;i++)for (ll j=0;j<w;j++)x[i][j]=0;
    vector<string> ss(h);
    for (ll i=0;i<h;i++)cin >> ss[i];
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (ss[i][j]=='#'){
                for (ll k=i-1;k<=i+1;++k){
                    for (ll l=j-1;l<=j+1;++l){
                        if (k<0 || l<0 || k>=h || l>=w)continue;
                        x[k][l]++;
                    }
                }
            }
        }
    }
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (ss[i][j]=='#')cout << '#';
            else cout << x[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<short> V;
const int UF=0,UL=1,UB=2,UR=3;
const int DF=4,DL=5,DB=6,DR=7;
set<int> S;
V A(8),num(8,-1);

void SW(int a,int b){swap(num[a],num[b]);}
void rot(){
  SW(UF,UR),SW(UR,UB),SW(UB,UL);
  SW(DF,DR),SW(DR,DB),SW(DB,DL);
}

void rot90(){
  V tmp = num;
  num[UF] = tmp[DF];
  num[UL] = tmp[DL];
  num[UB] = tmp[UL];
  num[UR] = tmp[UF];
  
  num[DF] = tmp[DR];
  num[DL] = tmp[DB];
  num[DB] = tmp[UB];
  num[DR] = tmp[UR];
  
  
}
void rev(){SW(UF,DB),SW(DF,UB),SW(UR,DR),SW(UL,DL);}

int VtoI(V&a=num){
  int res=0;
  for(int i=0;i<8;i++)res=res*10+num[i]+1;
  return res;
}

void RotRev(){
  for(int i=0;i<4;i++) rot(),S.insert(VtoI());
  rev();
  for(int i=0;i<4;i++) rot(),S.insert(VtoI());
  rev();
  
}

void Insert(){
  RotRev();
  rot90(),RotRev();
  rot(),rot90(),RotRev();
}

int check(){
  if(S.count(VtoI()))return 0;
  V tmp = num;
  Insert();
  num= tmp;
  return 1;
}

int dfs(int dep){
  if(dep==8) return check();
  int res=0;
  for(int i=0;i<8;i++){
    if(num[i]!=-1)continue;
    num[i] = A[dep];
    res+=dfs(dep+1);
    num[i] = -1;
  }
  return res;
}

int main(){
  while(1){
    map<string,int> M;
    string str;
    for(int i=0,cnt=0;i<8;i++){
      if((cin>>str)==0)return 0;
      if(M.count(str)) A[i] = M[str];
      else A[i] = M[str] = cnt++;
    }
    S.clear();
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5040
#include <stdio.h>
int main(){
  int n, a, i, j, x=0, t;

  int d[200];


  while(1){
    x = 0;
    scanf("%d", &n);
    if(n==0)break;
    for(i = 0; i < n; i++)    
      scanf("%d", &d[i]);
    
    for(i = n; i > 0; i--){
      
      for(j = 0; j+1< i ; j++)
	{
	  if(d[j] > d[j+1])
	    { 
	      t = d[j];
	      d[j] = d[j+1];
	      d[j+1] = t;
	      x++  ;
	    }
	}
    }
    printf("%d\n", x);
  }

  return 0;
}

Measured memory_bytes: 600
# coding: utf-8
# Your code here!
import heapq as hq

N,M=map(int,input().split())
A=[]

for i in range(N):
    a,b=map(int,input().split())
    A.append([a,b])
    
hq.heapify(A)
ans=0

while True:
    a,b=hq.heappop(A)
    ans+=(a*min(b,M))
    M-=min(b,M)
    if M==0:
        break
    
print(ans)
    


Measured memory_bytes: 19680
N,K = map(int, input().split())
A = []
for i in range(N): A.append(0)

for i in range(K):
    di = int(input())
    Ai = list(map(int, input().split()))
    for j in range(len(Ai)):
        A[Ai[j]-1] += 1

counter = 0
for i in range(N):
    if A[i] == 0:
        counter += 1
print(counter)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int lcm(int a, int b)
{
    return a / __gcd(a, b) * b;
}
int logn(int n, int r)
{
    return log(n) / log(r);
}
map<int, int> mp;
void solve()
{

    int l, r, d;

    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r;i++)
    {
        if(i%d==0){
            ans++;
        }
    }
        cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
using namespace  std;
int main()
{
	int a[5];
	for (int i = 0; i < 5; i++)
		cin >> a[i];
	for (int i = 0; i < 4; i++)
		for (int j = i + 1,t; j < 5; j++)
			if (a[i] < a[j])
			{
				t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
	for (int i = 0; i < 5; i++)
	{
		if (i != 0)cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
int main() {
	int a,b,c,f=0;
	scanf("%d%d%d",&a,&b,&c);
	for (int i=0;i<b;i++)if((a*i)%b==c)f=1;
	puts(f==1?"YES":"NO");
	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
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 ll inf = 1ll << 60;


int main() {
    int h, w;
    scanf("%d%d", &h, &w);
    vector<vector<int>> map(h, vector<int>(w));
    rp(i, 0, h ) {
        rp(j, 0, w) {
            char now;
            scanf(" %c", &now);
            if(now == '.') map.at(i).at(j) = 1;
            else if(now == '#') map.at(i).at(j) = 0;
            else {
                printf("error!");
                return 0;
            }
        }
    }
    vector<vector<ll>> dp(2050, vector<ll>(2050, 0ll));
    dp.at(0).at(0) = 1ll;
    rp(i, 0, h) {
        rp(j, 0, w) {
        if(i != 0 || j != 0) {
            if(map.at(i).at(j)) {
                ll res = 0;
                if(i > 0) res += dp.at(i-1).at(j);
                if(j > 0) res += dp.at(i).at(j-1);
                res %= mod;
                dp.at(i).at(j) = res;
            }
        }
        }
    }
    printf("%lld", dp.at(h-1).at(w-1));
    return 0;
} 

Measured memory_bytes: 37120