akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;

int main() {
	string s; cin >> s;
	int n = s.length();
	rep(i, n) {
		Rep(j, i, n+1) {
			string x;
			rep(k, n) {
				if (i <= k && k < j)continue;
				x.push_back(s[k]);
			}
			if (x == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
		return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n;
	char s[100];
	int x=0;
	int max_x=0;
	int i;

	scanf("%d",&n);
	scanf("%s",s);

	for(i=0;i<n;i++){
		if(s[i] == 'I')
			x++;
		else if(s[i] == 'D')
			x--;

		if(x > max_x)
			max_x = x;
	}

	printf("%d\n",max_x);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    string s;
    cin >> s;
    
    vector<int> alph(26);
    for(int i = 0;i < s.size();i++){
        alph[s[i] - 'A']++;
    }
    int cnt = 0;
    for(int i = 0;i < 26;i++){
        if(alph[i] == 2){
            cnt++;
        }
    }
    
    if(cnt == 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


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

int		main(void)
{
	char	a;	cin >> a;
	char	b;	cin >> b;
	if (a != b)
		cout << (a > b ? ">" : "<") << endl;
	else
		cout << "=" << endl;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long 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;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int d, n;
	cin >> d >> n;
	int a = 1;
	REP(i, d)a *= 100;
	if (n == 100)n = 101;
	cout << a * n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};


bool vis[107][107];
int dis[107][107];

struct nod{
	int x, y, d;
	nod(int x_, int y_, int d_){
		x = x_;
		y = y_;
		d = d_;
	}
};

bool ok(int x, int y, int n, int m){
	return 0 <= x && x < n && 0 <= y && y < m;
}

int shortestPathBinaryMatrix(vector<vector<int>>& g) {
	clr(dis,0);
	int n = (int)g.size();
	int m = (int)g[0].size();
	
	queue<nod> q;
	q.push(nod(0,0,1));
	vis[0][0] = true;
	dis[0][0] = 1;
	while(!q.empty()){
		int x = q.front().x;
		int y = q.front().y;
		int d = q.front().d;
		q.pop();
		for(int k = 0; k < 8; k++){
			int a = x + dx[k];
			int b = y + dy[k];
			if(ok(a,b,n,m) && !vis[a][b] && g[a][b] == 0){
				vis[a][b] = true;
				dis[a][b] = d + 1;
				q.push(nod(a,b,d+1));
			}
		}
	}
	if(dis[n-1][n-1] != 0)
		return dis[n-1][n-1];
    return -1;
}

char v[10] = {'#','1','2','3','4','5','6','7','8','9'};
vector<string> p; 
void perm(int l, int r){
	
	if(l == r){
		string str = "";
		for(int i = 1; i <= r; i++){
			
			str += v[i];
		}
		
		p.push_back(str);
		return;
	}
	
	for(int i = l; i <= r; i++){
		swap(v[l],v[i]);
		perm(l+1,r);
		swap(v[l],v[i]);
	}
}

int main()
{	
	
	int n; cin>>n;
	string s1="", s2="";
	for(int i = 0; i < n; i++){
		int x; cin>> x;
		s1 += (x+'0');
	}
	for(int i = 0; i < n; i++){
		int x; cin>> x;
		s2 += (x+'0');
	}
	
	perm(1,n);
	sort(p.begin(), p.end());
	int a, b;
	for(int i = 0; i < (int)p.size(); i++){
		if(p[i].compare(s1) == 0)
			a = i;
		if(p[i].compare(s2) == 0)
			b = i;
	}
	cout<<abs(a-b)<<endl;
	return 0;
}


Measured memory_bytes: 2424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.charAt(0) == s.charAt(1) && s.charAt(1)== s.charAt(2) || s.charAt(1) == s.charAt(2) && s.charAt(2)== s.charAt(3)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]Colorful Transceivers
            var line = ReadLine();
            int a =line[0];
            int b = line[1];
            int c = line[2];
            int d = line[3];
            
            if(Math.Abs(a - c) <=d | (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d))
            {
                Console.WriteLine("Yes");    
            }else
            {
                Console.WriteLine("No");    
            }
        }
        
        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cassert>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	ll n;
	scanf("%lld",&n);
	int k;
	scanf("%d",&k);
	ll ret=0;
	for(int i=0;i<=4;i++)
	{
		for(int j=0;j<11;j++)
		{
			int cnt=0;
			for(int x=j;x<j+3;x++)
			{
				for(int y=i;y<i+3;y++)
				{
					cnt+=7*(x+1)+(y+1)+4;
				}
			}
			//if(cnt%11==k) printf("%d %d\n",j+1,i);
			if(cnt%11==k&&n>=j+3) ret+=(n-j-3)/11+1;//,printf("%d %d\n",j,i);
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 128
import sys

def main():
    #N個の入力はいつものmapをlistとして受け取る
    N = int(input())
    A = list(map(int, input().split()))

    #演算回数をカウントする変数を定義
    ct = 0
    #ループを回す。
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] = A[i] // 2
            else:
                print(ct)
                sys.exit()
        ct += 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    int a,b,c,d,sum=0;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}

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

int main(){
  long int n, m, l, A[100][100], B[100][100], C[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> A[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> B[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }
  for(int i=0;i<n;i++){
				for(int j=0;j<l;j++){
					if(j!=l-1)cout<<C[i][j]<<" ";
					else cout<<C[i][j]<<endl;
				}
			}
}



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

double distance(const vector<int> &x, const vector<int> &y,
               const size_t dimension) {
  double result = 0;
  for (size_t i = 0; i < dimension; i++) {
    double diff = x[i] - y[i];
    result += pow(diff, 2);
  }
  return sqrt(result);
}

int main() {
  size_t N, D;
  cin >> N >> D;

  // D 次元のベクトルが n 個
  vector<vector<int>> matrix(N, vector<int>(D));

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

  // 距離が整数になる個数を計算する
  int number = 0;
  for (size_t i = 0; i < N; i++) {
    for (size_t j = i + 1; j < N; j++) {
      float d = distance(matrix[i], matrix[j], D);
      if (floor(d) == d) {
        number++;
      }
    }
  }
  cout << number << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;

int n, m;
vector<string> a;
vector<string> b;

bool judge(int y, int x) {
    bool f = true;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            if (b[i][j] != a[i+y][j+x]) f = false;
        }
    }
    return f;
}

int main(int argc, char const *argv[]) {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        string t;
        cin >> t;
        a.push_back(t);
    }
    for (int i = 0; i < m; ++i) {
        string t;
        cin >> t;
        b.push_back(t);
    }
    for (int i = 0; i < n-m+1; ++i) {
        for (int j = 0; j < n-m+1; ++j) {
            bool f = judge(i, j);
            if (f) {
                cout << "Yes" << std::endl;
                return 0;
            }
        }
    }
    cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=305;
const int mod=1e9+7;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,m;
int f[maxn][maxn][maxn];
typedef pair<int,int> pii;
vector<pii> pos[maxn];
int main(){
	n=read(),m=read();
	int l,r,x;
	for(int i=1;i<=m;i++){
		l=read(),r=read(),x=read();
		pos[r].push_back(pii(l,x));
	}
	f[1][0][0]=1;
	for(int i=1;i<=n;i++){
		int len=pos[i].size();
		for(int j=0;j<len;j++){
			int l=pos[i][j].first,x=pos[i][j].second;
			for(int k=0;k<i;k++){
				for(int p=0;p<=max(0,k-1);p++){
					if(x==1){if(l<=k)f[i][k][p]=0;}
					else if(x==2){if(k<l||l<=p)f[i][k][p]=0;}
					else if(p<l)f[i][k][p]=0;
				}
			}
		}
		if(i==0)break;
		for(int j=0;j<i;j++){
			for(int k=0;k<=max(0,j-1);k++){
				if(!f[i][j][k])continue;
				else{
					f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%mod;
					f[i+1][i][k]=(f[i+1][i][k]+f[i][j][k])%mod;
					f[i+1][i][j]=(f[i+1][i][j]+f[i][j][k])%mod;
				}
			}
		}
	}
	int ans=0;
	for(int j=0;j<n;j++)
	for(int k=0;k<=max(0,j-1);k++)
	ans=(ans+f[n][j][k])%mod;
	ans=((ans+ans)%mod+ans)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 108800
h,w=map(int,input().split())
field=["."*(w+2)]+["."+input()+"." for i in range(h)]+["."*(w+2)];flag=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if field[i][j]=="#":
      if "#" not in [field[i-1][j],field[i+1][j],field[i][j-1],field[i][j+1]]:
        flag=1
        break
if flag==0:print("Yes")
else:print("No")

Measured memory_bytes: 3064
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 26;
const int D = 365;

int d;

int c[N];
int s[D][N];

vi ans;

int last[N];
int evaluate(const vi& t){
    memset(last, 0, sizeof last);
    int ret = 0;
    FOR(i,t.size()){
        ret += s[i][t[i]];
        last[t[i]] = i+1;

        FOR(j,N){
            ret -= c[j] * (i+1 - last[j]);
        }
    }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>d;
    FOR(i,N)cin>>c[i];
    FOR(i,d){
    	FOR(j,N){
    		cin>>s[i][j];
    	}
    }

    FOR(i,d){
        // bruteforce
        int best = -1, vbest = -OO;
        FOR(j,N){
            ans.pb(j);
            int v = evaluate(ans);
            if(v > vbest){
                vbest = v;
                best = j;
            }
            ans.pop_back();
        }

        ans.pb(best);
    }

    int cbest = evaluate(ans);

    // hill climb
    REP(i,1,10000){
        int a, b;
        a = irand(0, d-1);
        b = irand(0, N-1);

        swap(ans[a], b);
        int tv = evaluate(ans);
        // cerr << "test " << tv << endl;
        if(tv > cbest){
            cbest = tv;
        }else{
            swap(ans[a], b);
        }
    }

    FOR(i,d){
        cout << ans[i]+1 << endl;
    }


    cerr << "final: " << evaluate(ans) << endl;

    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>

using namespace std;
#define ll long long
#define ve vector
#define umap unordered_map

const int MxN=1e5+1;
int t[MxN], mp[MxN], mx[MxN];

int main() {
    int n; cin>>n;
    int sum=0;
    for(int i=0;i<n;i++) {
        cin>>t[i];
        sum+=t[i];
    }
    int m; cin>>m;
    for(int i=0;i<m;i++) cin>>mp[i]>>mx[i];
    for(int i=0;i<m;i++) {
        cout<<sum-t[mp[i]-1]+mx[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,dp[10][10],dp2[10][10],ans;
string s;
int f(int x){
    while(x>9)x/=10;
    return x;
}
int f2(int x){
    return x%10;
}
int main(void){
    cin>>n;
    for(int i=1;i<=n;i++){
        //cout<<f(i)<<" "<<f2(i)<<endl;
        dp[f(i)][f2(i)]++;
        dp2[f2(i)][f(i)]++;
    }
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            ans+=dp[i][j]*dp2[i][j];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,n;
//	cout<<setprecision(10);
	cin>>n;
	ll ar[n];
	ll f[n+1]={0};
	for(i=0;i<n;i++)
	{
		cin>>ar[i];
		f[ar[i]]++;
	}
	ll ans=0;
	for(i=0;i<=n;i++)
	{
		ans+=f[i]*(f[i]-1)/2;
	}
	for(i=0;i<n;i++)
	{
		ll x=ans;
		x-=f[ar[i]]*(f[ar[i]]-1)/2;
		ll y=f[ar[i]]-1;
		x+=y*(y-1)/2;
		cout<<x<<endl;
	}
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b,n;
  cin>>a>>b>>n;
  if(b<=n){
    if(a>=b){
 long long g=n/b;
   long long d=(a*(g*b-1))/b-a*(g-1);
  
  cout<<d<<endl;
  }
    else {
      cout<<a-1<<endl;
    }
  }
  else{
    cout<<a*n/b<<endl;
}
}
  

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

int main() {
  int K;
  string S;
  cin>>K>>S;

  if(S.size()<=K){cout<<S<<endl;}
  else{rep(i,K){cout<<S.at(i);}cout<<"..."<<endl;}
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
  string s;
  cin>>s;
  s.push_back('?');
  
  for(int i=0;i<(int)s.size()-1;i++){
    if(s[i]==s[i+1]){
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
    if(s[i]==s[i+2]){
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
}


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

int main()
{
    long long n,m;
    cin>>n>>m;
    if(n==1&&m==1)
        cout<<1<<endl;
    else
        if(n==1||m==1)
            cout<<n*m-2<<endl;
        else
            if(n==2||m==2)
                cout<<0<<endl;
            else
            {
                cout<<(n-2)*(m-2)<<endl;
            }




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int n;
int a[2002];
pii p[2002];
LL dp[2002][2002];
LL dfs(int s, int e){
    if(s > e) return 0;
    if(dp[s][e] != -1) return dp[s][e];
    int idx = s-1 + n-e + 1;
    return dp[s][e] = max(dfs(s+1, e) + abs(s-p[idx].second)*1ll*p[idx].first, dfs(s, e-1) + abs(e-p[idx].second)*1ll*p[idx].first);
}
int main(){
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        p[i] = pii(a[i], i);
    }   
    sort(p+1, p+1+n);
    reverse(p+1, p+1+n);
    memset(dp, -1, sizeof(dp));
    printf("%lld\n", dfs(1, n));
}

Measured memory_bytes: 35264
n = int(input())
AB = list(list(map(int,input().split())) for _ in range(n))
CD = list(list(map(int,input().split())) for _ in range(n))

CD.sort() # sort x in ascending order
AB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order

dim_b = [[] for _ in range(n)]
for b in range(n):
    bx, by = CD[b]
    for r in range(n):
        rx, ry = AB[r]
        if rx < bx and ry < by: dim_b[b] += [r]

vis_r = [False]*(n)
for b in range(n): # ascending order of x
    max_ry = max_r = -1
    for r in dim_b[b]: # descending order of y
        if vis_r[r]: continue
        rx, ry = AB[r]
        if max_ry < ry:
            max_ry = ry
            max_r = r
    if max_r >= 0: vis_r[max_r] = True
print(sum(vis_r))


Measured memory_bytes: 3188
from collections import deque

K = int(input())

while K%2 == 0:
  K //= 2
while K%5 == 0:
  K //= 5

if K == 1:
  print(1)
  exit()

q0 = [1]
q1 = []

T = [2]*K
T[1] = 0

x = 1

while True:
  while q0:
    v = q0.pop()
    a = (v+1)%K
    if T[a] > 1:
      q1.append(a)
      T[a] = 1
    b = (v*10)%K
    if T[b] > 0:
      q0.append(b)
      T[b] = 0
  if T[0] <= 1:
    print(x+T[0])
    exit()
  q0 = q1
  q1 = []
  x += 1


Measured memory_bytes: 6168
n,w=map(int,input().split())
wv=[]
dp=[[0 for i in range(100010)]for j in range(110)]
for i in range(n):
    a=[int(j) for j in input().split()]
    wv.append(a)

from operator import itemgetter
wv.sort(key=itemgetter(0))

for i in range(n):
    for j in range(w+1):
        if j>=wv[i][0]:
            dp[i+1][j]=max(dp[i][j],dp[i][j-wv[i][0]]+wv[i][1])
        else:
            dp[i+1][j]=dp[i][j]


print(dp[n][w])

Measured memory_bytes: 181512
#include <stdio.h>
int main(void)
{
       
    int h,w,H,W;
    for(;;){
        scanf("%d %d",&H,&W);
    if(H==0 && W==0)break;
    for(h=0; h<H; h++){
        for(w=0; w<W; w++){
            printf("#");
            
        }
        printf("\n");
        
    }
    printf("\n");
    }
    return 0;  
 
    
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}

int power(int N, int M) {return M ? power(N * N, M / 2) * (M % 2 ? N : 1) : 1;}

int mystoi(string S){
    int num = 0;
    for (int i = (int) S.length()-1; i >= 0; i--){
        num += (S[i]-'0') * power(10,S.length()-1-i);
    }
    return num;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int A;
    string B;
    cin >> A >> B;
    int C = mystoi(B.substr(0,SZ(B)-3));
    C *= 100;
    C += mystoi(B.substr(SZ(B)-2,2));
    ans = A*C;
    ans /= 100;
    pa;

    
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_c && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_c && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_c && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(n); ++i)
#define REP(i, d, n) for(long long i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

int x; cin>>x;
  if(x==0){cout<<1<<endl;}

  else{cout<<0<<endl;}
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;


int main() {

	int N;
	int64_t a;
	int64_t ans;
	double test;

	cin >> N;

	cin >> ans;
	test = ans;

	for (int i = 0; i < N -1; i++)
	{
		cin >> a;
		ans *= a;
		test *= a;
	}

	if (ans > 1000000000000000000 || test > 1000000000000000000) {
		cout << "-1";
	}
	else
	{
		cout << ans;
	}

	return 0;

}

Measured memory_bytes: 3632
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s;
    cin >> s;

    ll sum = 0;
    REP(i, s.size()) {
        sum += s[i] - '0';
    }

    print((sum % 9) == 0 ? "Yes" : "No");
    
}


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

int main() {
	// your code goes here
	int x,y;//a+b=x;2*a + 4*b=y;
	cin>>x>>y;
	if(y-2*x>=0 && (y-2*x)%2==0 && x-((y-2*x)/2) >=0)
	  cout<<"Yes";
	else cout<<"No";  
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans,a[100100];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        if(i+1>a[i+1]){
               for(int j=i+1;a[j]==i;j++) ans^=1;
               ans|=(a[i]-i)&1;
               puts(ans? "First":"Second");
               return 0;
           }    
    }    
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e6+1;
int p[N], n, a[N], cnt[N];

long POW(long x, long n){
  if (n == 0) return 1;
  long y = POW(x, n / 2);
  y = y * y % MOD;
  if (n % 2) return x * y % MOD;
  else return y;
}

int main()
{
  fastio;
  for (int i = 1; i < N; i++) p[i] = i;
  for (int i = 2; i * i < N; i++){
    if (p[i] == i){
      for (int j = i * i; j < N; j += i){
        if (p[j] == j) p[j] = i;
      }
    }
  }
  int n; cin >> n;
  for (int i = 1; i <= n; i++){
    int x; cin >> x; a[i] = x;
    vector <pii> memo;
    while (x != 1){
      int d = 0; int y = p[x];
      while (x % y == 0){
        x /= y;
        d++;
      }  
      memo.push_back(pii(y, d));
    }
    for (pii x : memo) cnt[x.first] = max(cnt[x.first], x.second);
  }
  long lcm = 1;
  for (int i = 2; i < N; i++){
    lcm *= POW(i, cnt[i]);
    lcm %= MOD;
  }
  long res = 0;
  for (int i = 1; i <= n; i++){
    res = (res + lcm * POW(a[i], MOD - 2));
    res %= MOD;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 9600
a = list(map(int, input().split()))
alice = 0
bob = 0
ans = 0
for i in range(0, 101):
    if i == a[0]:
        alice = 1
    if i == a[1]:
        alice = 0
    if i == a[2]:
        bob = 1
    if i == a[3]:
        bob = 0

    ans += alice * bob
print(ans)


Measured memory_bytes: 3060
#include <functional>
#include <random>
#include <cassert>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;

long long L1(long long a, long long b, long long c, long long d) {
    return abs(a - c) + abs(b - d);
}

long long L1(pair<long long, long long> p, pair<long long, long long> q) {
    return L1(p.first, p.second, q.first, q.second);
}

bool check(int x, int y, int k, vector<pair<int, int> > &ans) {
    for (int i = 0; i < ans.size(); i++) {
        auto prev = i > 0 ? ans[i-1] : make_pair(0, 0);
        if (L1(prev, ans[i]) != k) return false;
    }
    return ans.back() == make_pair(x, y);
}

vector<pair<int, int> > construct(int x, int y, long long k) {
    vector<pair<int, int> > ans;
    int a = 0, b = 0;
    while (L1(a, b, x, y) > 2 * k) {
        if (a + k <= x) a += k;
        else if (a < x) {
            b += k - (x - a);
            a = x;
        } else {
            b += k;
        }
        ans.emplace_back(a, b);
    }

    if (L1(a, b, x, y) % 2 == 1) {
        assert (L1(a, b, x, y) % 2 == 1);
        if (x - a > y - b) a += k;
        else b += k;
        ans.emplace_back(a, b);
    }

    function<pair<int, int>(long long)> getpoint = [&](long long i) {
        long long q = i / k, r = i % k;
        switch (q) {
        case 0: return make_pair(a + k - r, b + r);
        case 1: return make_pair(a - r, b + k - r);
        case 2: return make_pair(a - k + r, b - r);
        case 3: return make_pair(a + r, b - k + r);
        default: assert(false);
        }
    };
    function<int(long long)> dist = [&](long long i) {
        return L1(getpoint(i), {x, y});
    };
    long long lb = -1, ub = -1;
    for (int i = 0; i < 4; i++) {
        if (dist(i * k) > k) ub = i * k;
        else lb = i * k;
    }
    assert(lb >= 0);
    assert(ub >= 0);
    while (abs(lb - ub) > 1) {
        long long m = (lb + ub) / 2;
        if (dist(m) > k) ub = m;
        else lb = m;
    }
    ans.emplace_back(getpoint(lb));
    ans.emplace_back(x, y);
    return ans;
}

int main() {
    int k, x, y; cin >> k >> x >> y;
    const int d = abs(x) + abs(y);
    if (k % 2 == 0 && d % 2 == 1) {
        cout << "-1\n";
        return 0;
    }
    if (L1(0, 0, x, y) == k) {
        cout << "1\n" << x << " " << y << endl;
        return 0;
    }
    bool negx = x < 0, negy = y < 0;
    x = abs(x); y = abs(y);
    vector<pair<int, int> > ans = construct(x, y, k);
    cout << ans.size() << endl;
    for (auto [a, b] : ans)
        cout << (negx ? -a : a) << " " << (negy ? -b : b) << endl;
    // assert(check(x, y, k, ans));
}


Measured memory_bytes: 4828
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

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

    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m)
            cin >> a[i][j];
    }

    int ans = INF9;
    for(int is = 0; is < (1 << n); ++is){
        int cost = 0;
        vector<int> us(m, 0);
        rep(i, n){
            if(is & (1 << i)){
                cost += c[i];
                rep(j, m)
                    us[j] += a[i][j];
            }
        }

        rep(j, m){
            if(us[j] < x) break;
            if(j == m - 1) chmin(ans, cost);
        }
    }

    cout << (ans == INF9 ? -1 : ans) << endl;

return 0;
}

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

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

    long long ans=0;
    int t1,t2=0;
    for(int i=0;i<N;i++){
        cin >> t1;
        if(i!=0){
            if(t1-t2>T) ans+=T;
            else ans+=t1-t2;
        }
        if(i==N-1) ans+=T;
        t2=t1;
    }
    cout << ans << endl;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef unsigned long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A.at(i); }
  sort(A.begin(), A.end(), greater<ll>());
  if (A.at(N - 1) == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll const MAX = 1000000000000000000;
  ll ans = 1ll;
  ll prev_ans = ans;

  REP(i, N) {
    ans *= A.at(i);
    if (ans / A.at(i) != prev_ans) {
      ans = -1;
      break;
    }
    prev_ans = ans;
  }

  if (ans > MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4004
#!/mnt/c/Users/moiki/bash/env/bin/python
import sys
N,M  = map(int, input().split())
# N = int(input())
REQ  = [ [int(j) for j in line.split()] for line in sys.stdin.readlines()]
REQ = sorted(REQ, key=lambda x: x[1])

ans = 0
end  = -1
for i in range(M):
    r = REQ[i]

    if r[0] < end <= r[1]:
        continue
    else:
        end = r[1]
        ans += 1
print(ans)
        




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

int main(void) {
    int N, M;
    int A;
    
    cin >> N >> M;
    
    int ans = N;
    
    for (int i = 0; i < M; i ++) {
        cin >> A;
        ans -= A;
    }
    
    if (ans >= 0) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3624
def most_char_count(char_arr)
  3 - char_arr.map{|char| char_arr.count(char)}.max
end

input = readlines
n = input[0].to_i
str_list = input[1..3].map(&:chomp)

puts (0...n).to_a.map{|i| most_char_count(str_list.map{|str| str[i]})}.inject(:+)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;
  for(int i=0; i<S.size(); i++){
    S[i] = (S[i]-'A'+N)%26 + 'A';
  }
  cout << S << endl;
  return 0;
}

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

// ---------------------------template starts here-------------------------- 

#define int long long int
#define pb push_back
#define MAX INT_MAX
#define endl "\n"
#define precise std::cout << std::fixed;std::cout << std::setprecision(6); 
#define F first
#define S second  
#define mp make_pair
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

int binexpo(int x, int y, int p) {    
    int res = 1;     // Initialize result  
    x = x % p; // Update x if it is more than or  
                // equal to p  

    while (y > 0)  {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;
}
// --------------------------template ends here------------------------------

void solve() {
    int n, m;
    cin >> n >> m;
        if(n%m == 0)
            cout << '0' << endl;
        else {
            int rem = n%m;
            cout << min(rem, m-rem) << endl;
    }     

    return;
}

int32_t main() {
    FO;
    solve();
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 1LL << 50;
const ll mod = 1000000007;




int main() {
	int n, m;
	cin >> n >> m;
	VI a(m), b(m), c(m);
	REP(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
	}
	VLL v(1000, INFL);
	v[0] = 0;
	REP(loop, n - 1) {
		REP(i, m) {
			if (v[a[i] - 1] == INFL)continue;
			if (v[b[i] - 1] > v[a[i] - 1] + c[i]) {
				v[b[i] - 1] = v[a[i] - 1] + c[i];
			}
		}
	}

	bool d[1000];
	REP(i, n)d[i] = false;

	REP(loop, n) {
		REP(i, m) {
			if (v[a[i] - 1] == INFL)continue;

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

			if (d[a[i] - 1] == true) d[b[i] - 1] = true;
		}
	}
	if (d[n - 1])cout << "inf" << endl;
	else cout << -v[n-1] << endl;


	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
char mas[100][100];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int sx,sy,gx,gy,w,h,cnt;

void dfs(int x,int y,char c);

main(){
  while(1){
    cnt=0;
    cin >> h >> w;
    if(w==0 && h==0){
      break;
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> mas[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(mas[i][j]!='.'){
	  cnt++;
	  dfs(j,i,mas[i][j]);
	}
      }
    }
    cout << cnt << endl;
  }
}

void dfs(int x,int y,char c){
  mas[y][x]='.';
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx>=0 && nx<w && ny>=0 && ny<h && mas[ny][nx]==c){
      dfs(nx,ny,c);
    }
  }
}
      

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  bool ok=0;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%k==0) ok=1;
  }
  if(ok==1) cout <<"OK";
  else cout << "NG";
  return 0;
}

Measured memory_bytes: 3520
fun main(arr:Array<String>) {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val monsterList = readLine()!!.split(" ").map { it.toLong() }.sortedDescending()
    val ans = monsterList.drop(Math.min(k, monsterList.size)).sum()
    println(ans)
}



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

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\a.txt","r",stdin);
	char str[100000];
	while ( ~scanf("%s", str) ) {
		int number[4] = {0,0,0,0};
		for (int i = 0; i < strlen(str); ++i)
		{
			if ( str[i] == 'N' )
			{
				number[0]++;
			}
			if ( str[i] == 'S' )
			{
				number[1]++;
			}
			if ( str[i] == 'W' )
			{
				number[2]++;
			}
			if ( str[i] == 'E' )
			{
				number[3]++;
			}
		}
		int ret = 0;
		if( number[0] == 0 && number[1] == 0 || number[0] != 0 && number[1] != 0 ) {
			if( number[2] == 0 && number[3] == 0 || number[2] != 0 && number[3] != 0 ) {
				ret = 1;
			}
		}
		if ( ret )
		{
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  int main(){
int N;
  cin>>N;
  set<int>S;
  for(int i=0;i<N;i++){
  int x;
    cin>>x;
  S.insert(x);
  }int ans=S.size();
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1);I >= (A); --I)
const ll INF=1e18+3;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	if(s.size()<4){
		cout<<"No"<<endl;
	}else if(s.substr(0,4)=="YAKI"){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,a=map(int,input().split())
x=[0]+list(map(int,input().split()))
su=sum(x)
maxi=max(x)
dp=[[[0 for k in range(maxi*n+1)] for j in range(51)] for i in range(51)]
dp[0][0][0]=1
for i in range(1,n+1):
    for j in range(i+1):
        for k in range(maxi*j+1):
            if k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            if k>=x[i] and j>=1:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]
ans=0
for t in range(1,n+1):
    if a*t<=su:
        ans+=dp[n][t][a*t]
    else:
        break
print(ans)


Measured memory_bytes: 65520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		String S = sc.next();
		char[] arr = S.toCharArray();
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < arr.length; i++){
			if(i == K - 1){
				sb.append((char) (arr[i] - 'A' + 'a'));
			}else{
				sb.append(arr[i]);
			}
		}
		
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 23764
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class ATransfer {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
            int available = a - b;
            int ans = 0;
            if (available >= c)
                ans = c;
            else
                ans = available;
            out.println(c - ans);
        }

    }
}



Measured memory_bytes: 23764
import kotlin.math.abs
import kotlin.math.min

fun main() = msolutions2020e()

@OptIn(ExperimentalStdlibApi::class)
fun msolutions2020e() {
    val n = readLine()!!.toInt()
    val xList = IntArray(n)
    val yList = IntArray(n)
    val pList = IntArray(n)
    repeat(n) { i ->
        val (x, y, p) = readLine()!!.split(" ").map { it.toInt() }
        xList[i] = x
        yList[i] = y
        pList[i] = p
    }

    val choosePatterns = 1 shl n
    // 何もしてないのときの移動距離
    val baseDistances = (0 until n).map { min(abs(yList[it]), abs(xList[it])) }.toIntArray()
    // [その集合の街を基準に『横』に線路を引いたとき][i番目の街の] = 移動距離の最小
    val costsVert = Array(choosePatterns) { baseDistances.copyOf() }
    // [その集合の街を基準に『縦』に線路を引いたとき][i番目の街の] = 移動距離の最小
    val costsHorz = Array(choosePatterns) { baseDistances.copyOf() }

    val diffVert = Array(n) { IntArray(n) { Int.MAX_VALUE } }
    val diffHorz = Array(n) { IntArray(n) { Int.MAX_VALUE } }

    for (from in 0 until n) for (to in 0 until n) {
        diffVert[from][to] = min(diffVert[from][to], abs(yList[from] - yList[to]))
        diffHorz[from][to] = min(diffHorz[from][to], abs(xList[from] - xList[to]))
    }

    for (choose in 0 until choosePatterns) {
        for (from in (0 until n)) {
            if ((choose shr from) and 1 == 0) continue
            for (to in 0 until n) {
                costsVert[choose][to] = min(costsVert[choose][to], diffVert[from][to])
                costsHorz[choose][to] = min(costsHorz[choose][to], diffHorz[from][to])
            }
        }
    }

    val answers = LongArray(n + 1) { Long.MAX_VALUE }

    for (b in 0 until (3).simplePowExact(n)) {
        var chooseVertBit = 0
        var chooseHorzBit = 0
        var bitOfChooseTypes = b
        var bitOfDigit2 = 1

        while (bitOfChooseTypes > 0) {
            when (bitOfChooseTypes % 3) {
                1 -> chooseVertBit = chooseVertBit or bitOfDigit2
                2 -> chooseHorzBit = chooseHorzBit or bitOfDigit2
            }
            bitOfDigit2 = bitOfDigit2 shl 1
            bitOfChooseTypes /= 3
        }

        var costSum = 0L
        for (i in 0 until n) {
            costSum += min(costsVert[chooseVertBit][i], costsHorz[chooseHorzBit][i]).toLong() * pList[i]
        }

        val chooseCount = Integer.bitCount(chooseVertBit or chooseHorzBit)
        answers[chooseCount] = min(answers[chooseCount], costSum)
    }

    val answer = answers.joinToString(System.lineSeparator())

    println(answer)
}

private fun Int.simplePowExact(p: Int): Int {
    var x = 1
    repeat(p) { x = Math.multiplyExact(x, this) }
    return x
}


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

using namespace std;

long long dp[33];

int main() {
  int n;
  
  while( cin >> n, n ) {
    fill(dp, dp+32, 0);
    dp[0] = 1, dp[1] = 1, dp[2] = 2;
    for(int i=3; i<=n; i++) {
      dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    }
    cout << dp[n]/3650+1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1156