akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    cout << (((b*10 + c) % 4 == 0)?"YES":"NO") << endl;
    return 0;
}

Measured memory_bytes: 256
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	string s;
	cin>>s;
	for(auto it :s)
		cout<<"x";
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
int prime(int n)
{
 for(int i=2;i*i<=n;i++)
      {
          if(n%i==0)
          return 0;
      }
      return 1;
}
int gcd(int a, int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
int lcm(int a, int b)  
  {  
     return (a*b)/gcd(a, b);  
  } 
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {  
       int n;
       cin>>n;
       if(n%2)
       {
           cout<<0;
           return 0;
       }
       int x=0;
       n/=10;
       x+=n;
       while(n>=5)
       {
           n/=5;
           x+=n;
           
       }
       cout<<x;
        
        
    }
    
}
// 🍪 🍪 🍪


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

int main() {
	while (cin >> n, n) {
		string s;
		vector<int> v;
		for (int i = 0; i < n; i++) {
			cin >> s;
			v.push_back(s.length());
		}
		int a[] = { 5,7,5,7,7 };
		int b[] = {0,0,0,0,0};
		int sf = 0;
		int now = 0;
		int i = 0;
		while (1) {
			if (b[now] < a[now]) {
				b[now] += v[i];
				i++;
				continue;
			}
			else if (b[now] == a[now]) {
				if (now == 4)break;
				else {
					now++;
				}
			}
			else {
				sf++;
				now = 0;
				i = sf;
				for (int j = 0; j < 5; j++)b[j] = 0;
			}
		}
		cout << sf + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, W; cin >> N >> W;
    vector<int> weight(100001, W+1);
    weight[0] = 0;
    for (int i = 0; i < N; i++) {
        int w, v; cin >> w >> v;
        for (int j = 100000 - v; j >= 0; j--) {
            weight[j + v] = min(weight[j + v], weight[j] + w);
        }
    }
    for (int i = 100000; i >= 0; i--) {
        if (weight[i] <= W) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,A,B;cin>>N>>A>>B;
  
  if(N*A>=B){
    cout<<B<<endl;
  }
  else{
    cout<<N*A<<endl;
  }
}

Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

string s;

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

  ll ans = 0;
  ll a_num = 0;
  ll b_num = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' && b_num == 0) {
      a_num++;
    } else if (s[i] == 'B' && a_num > 0 && b_num == 0) {
      b_num++;
    } else if (s[i] == 'C' && a_num > 0 && b_num > 0) {
      ans += a_num;
      b_num = 0;
    } else {
      a_num = 0;
      b_num = 0;
      if (s[i] == 'A') {
        a_num++;
      }
    }
  }

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

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
const double PAI = acos(-1);
constexpr long double eps = 1e-9;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin>>n>>k;
    
    ll ret = 0;
    for(ll i=k;i<=n+1;++i){
        ll mi =(i-1)*i/2;
        ll ma =(n+(n-i+1))*i/2;
        (ret += ma - mi+1)%=mo;
    }
    cout << ret << endl;
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#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,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/

ll gcd(ll a,ll b){
  if(a<b) swap(a,b);
  if(a%b==0) return b;
  else return gcd(b,a%b);
}
int main() {
  ll n,k;
  cin >> n >> k;
  ll gc;
  ll mx = 0;
  REP(i,n){
    ll ai;
    cin >> ai;
    CHMAX(mx,ai);
    if(i==0) gc = ai;
    else gc = gcd(gc,ai);
  }
  string ans;
  if(k%gc==0) ans = "POSSIBLE";
  else ans = "IMPOSSIBLE";

  if(mx<k) ans = "IMPOSSIBLE";

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


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<algorithm>
#include<vector>

#define N 8
#define FREE -1
#define NOT_FREE 1

using namespace std;

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
bool X[N][N];

void initialize(){
	for(int i=0;i<N;i++){
		row[i]=FREE; col[i]=FREE;
	}
	for(int i=0;i<2*N-1;i++){
		dpos[i]=FREE; dneg[i]=FREE;
	}
}

void printBoard(){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(X[i][j]){
				if(row[i]!=j) return;
			}
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			printf((row[i]==j) ? "Q":".");
		}
		printf("\n");
	}
}

void recursive(int i){
	if(i==N){
		printBoard(); return;
	}
	for(int j=0;j<N;j++){
		//(i,j)?????????????????????????\????????±???§????????°, ??????.
		if(col[j]==NOT_FREE ||
					dpos[i+j]==NOT_FREE ||
					dneg[i-j+N-1]==NOT_FREE) continue;
		//(i,j)????????????????????????.
		row[i]=j;
		col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
		//?¬?????????????????????????.
		recursive(i+1);
		//(i,j)???????????????????????????????????????????????????.
		row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
	}
}

int main(){
	initialize();
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			X[i][j]=false;
		}
	}
	int k;
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		int r,c;
		scanf("%d %d",&r,&c);
		X[r][c]=true;
	}
	recursive(0);
}

Measured memory_bytes: 3220
#include <stdio.h>

int main(void){

	int a = 0;
	int b = 0;
	int c = 0;

	if(scanf("%d", &a) != -1 && scanf("%d", &b) != -1 && scanf("%d", &c) != -1){

		int price[3];

		price[0] = a + b;
		price[1] = b + c;
		price[2] = c + a;
	
		int lowest = price[0];

		for(int i = 1 ; i < 3; i++){

			if(lowest > price[i]){
				lowest = price[i];
			}
		}
	
		printf("%d",lowest);

	}

	return 0;

}

Measured memory_bytes: 128
zyouken = [int(i) for i in input().split()]
reizouko = [int(a) for a in input().split()]
densirenzi = [int(b) for b in input().split()]
minkouho = min(reizouko) + min(densirenzi)
while zyouken[2] > 0:
    zyouken[2] -= 1 
    waribiki = [int(w) for w in input().split()]
    mink = reizouko[waribiki[0] - 1] + densirenzi[waribiki[1] - 1] - waribiki[2]
    if mink < minkouho:
        minkouho = mink
print(minkouho)

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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
//template <class  T>T max(T x,T y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
///////////////////////////////////////////

int main(){
    ll h,w;
    cin>>h>>w;
    int map[55][55]={0};
    char input;
    int num=0;
    for (int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            cin>>input;
            if(input == '#'){
                map[i][j]=1;

            }
        }
    }
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            if(map[i][j]==1){
                if(map[i+1][j]==1){

                }else if(map[i-1][j]==1){

                }else if(map[i][j+1]==1){

                }else if(map[i][j-1]==1){

                }else{
                    num=1;
                    break;
                }
            }
        }
    }
    if(num==1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}


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

const int LLINF = 1LL << 60;

signed main()
{
  
  int Z[105], Y[1005];
  
  for(int i = 0; i <= 1000; i++) {
    if(i * i <= 1000000) {
      Y[i] = i * i;
    }
    if(i * i * i <= 1000000) {
      Z[i] = i * i * i;
    }
  }
  
  int E;
  while(cin >> E, E) {
    
    int minv = LLINF;
    
    for(int i = 0; i <= 100; i++) {
      for(int j = 0; j <= 1000; j++) {
	if(Z[i] + Y[j] <= E) {
	  minv = min(i + j + E - (Z[i] + Y[j]), minv);
	}
      }
    }
    
    cout << minv << endl;

  }
  
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int N;
    cin >>N;
    ll A[N];
    FOR(i,N){
        cin >>A[i];
    }
    ll R[N];
    R[0]=0;
    for(int i=0;i<N;i++){
        R[0]+=A[i]*pow(-1,i);
    }
    for(int i=1;i<N;i++){
        R[i]=2*A[i-1]-R[i-1];
    }

    FOR(i,N){
        if(i==0){
            cout<<R[i];
        }else{
            cout<<" "<<R[i];
        }
    }
    cout<<endl;
    //cout <<max<<endl;
    return 0;
}




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

int main()
{
    string S,T;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;
    if(S==U){
        A--;
    }else{
        B--;
    }
    cout << A <<" " << B << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = float('inf')


def LI(): return list(map(int, sys.stdin.readline().split()))


def I(): return int(sys.stdin.readline())


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

h,w,m= LI()
s=set()
D1=defaultdict(int)
D2=defaultdict(int)
for _ in range(m):
    h,w=LI()
    D1[h-1]+=1
    D2[w-1]+=1
    s.add((h-1,w-1))

A=[[v,i] for i,v in D1.items()]+[[-INF,-INF]]
B=[[v,i] for i,v in D2.items()]+[[-INF,-INF]]
A.sort(reverse=True)
B.sort(reverse=True)
a_now=0
b_now=0
ans=-INF
for i in range(3*10**5):
    av,ak=A[a_now]
    bv,bk = B[b_now]
    res=av+bv-int((ak,bk) in s)
    ans=max(ans,res)
    if a_now==len(A)-2 and b_now==len(B)-2:
        break
    elif A[a_now+1][0]+B[b_now][0]>A[a_now][0]+B[b_now+1][0]:
        a_now+=1
    else:
        b_now+=1

print(ans)






Measured memory_bytes: 209860
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

int sum(int n) {
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);  
	return s + n;  
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; 
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

//だから私は～
//#define int long long
// ===============================================================

/*signed*/int main() {
	ll a, b, e;
	cin >> a >> b >> e;
	ll g = a + b - e;
	ll f = a + g - e;
	ll c = a + e - f;
	ll h = a + e - g;
	ll i = b + e - g;
	ll d = c + i - e;
	cout << a << " " << b << " " << c << endl;
	cout << d << " " << e << " " << f << endl;
	cout << g << " " << h << " " << i << endl;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	vector<ll> a(n),b(n),c(n);
	for(ll i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(ll i=0;i<n;i++)
	{
		cin>>c[i];
		a[i]=i+1;
	}
	ll ans = 1;
	ll val , val2;
	do
	{
		if (b==a)
		{
			val = ans;
		}
		if (c==a)
		{
			val2 = ans;
		}
		ans++;
	}
	while(next_permutation(a.begin(),a.end()));
	cout<<abs(val-val2);
}

Measured memory_bytes: 256
import statistics
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
A = list(map(int,input().split()))
mean = statistics.mean(A)
print(A.index(getNearestValue(A,mean)))


Measured memory_bytes: 23516
#include<iostream>
#include<string>
#include<vector>
#include<cmath>

using namespace std;

const double PI = 3.1415926535;

int A, B, H, M;

int main() {
	cin >> A >> B >> H >> M;
	double ar, br;
	ar = (H * 60 + M) * 0.5;
	br = M * 6.0;
	double R = br - ar;
	double ans;
	ans = sqrt(A*A + B*B - 2*A*B*cos(R / 180 * PI));
	printf("%.9f", ans);
}

Measured memory_bytes: 4192
#include<stdio.h>

int main()
{
  int n,q,S[1000000],T[50000],i,j,number_of_coresspond = 0,left,mid,right;

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

  left = 0;
  right =n;
  mid = (left+right)/2;
 
  for(i = 0 ; i < q ; i++)
    {

      left = 0;
      right =n;
      mid = (left+right)/2;
      //printf("i = %d\n",i);
      
      while(left<right)
	{
	  //printf("left = %d  mid = %d  right = %d\n",left,mid,right);
	  if(S[mid] == T[i])
	    {
	      number_of_coresspond++;
	      break;
	    }
	  else if(S[mid] > T[i])
	    {
	      right = mid;
	      mid = (left + right)/2;
	    }
	  else if(S[mid] <T[i])
	    {
	      left = mid+1;
	      mid = (left + right)/2;
	    }
	  //printf("left = %d  mid = %d  right = %d\n",left,mid,right);

	}
      //printf("\n");
    }

  printf("%d\n",number_of_coresspond);
  
    

    

}



Measured memory_bytes: 2320
n = int(input())
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

def get_inv(n, f, invf, p=10**9 + 7):
    inv = [0]
    for i in range(n):
        inv.append(invf[i+1] * f[i] % p)
    return inv

f = fact(30+10**5)
invf = invfact(30+10**5, f)
inv = get_inv(30+10**5, f, invf)

def comb(a, b):
    return f[a] * invf[b] * invf[a-b] % p

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print(ans * f[n] % p)

Measured memory_bytes: 25124
#include<bits/stdc++.h>
 using namespace std;
int main(){
  string n;
  cin >> n;
  int res = 0;
  for (int i = 0; i < 4; i++) {
    if (n[i] == '+') {
      res++;
    }else{
      res--;
    }
  }

    cout << res << "\n";
}


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

using ll = long long;

const int MOD = 1e9 + 7;

int add(int a, int b) {
    return (a + b) % MOD;
}

int sub(int a, int b) {
    return (a - b + MOD) % MOD;
}

int mul(ll a, ll b) {
    return (a * b) % MOD;
}

int main() {
    int n, h, d;
    cin >> n >> h >> d;

    vector<int> f(n + 1);
    f[0] = 1;
    for (int i = 1; i <= n; i++)
        f[i] = mul(f[i - 1], i);

    int coef = accumulate(f.begin() + 1, f.end(), 0LL) % MOD;

    vector<int> dp(h + 1), pref(h + 2);
    dp[0] = 1, pref[1] = f[n];
    for (int i = 1; i <= h; i++) {
        dp[i] = sub(pref[i], pref[max(i - d, 0)]);
        pref[i + 1] = add(pref[i], mul(coef, dp[i]));
    }

    cout << dp[h] << endl;
}


Measured memory_bytes: 12032
from collections import deque
N = int(input())
A = deque([list(map(int, input().split())) for _ in range(N)])
A.appendleft([0, 0, 0])
counter = 0
for i in range(N):
    if not (sum(A[i]) + sum(A[i + 1])) % 2:
        d = sum([abs(A[i][j] - A[i + 1][j]) for j in range(1, 3)])
        if A[i + 1][0] - A[i][0] >= d:
            counter += 1
if counter == N:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 65368
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

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

	public static void main(String[] args) {
		new Main();	
	}

	public Main() {
		while(sc.hasNext()){
			new aoj0035().doIt();
		}
	}
	class aoj0035 {
		//?????????????????????EPS,Point2D????????????
		final double EPS = 1.0e-08;
		//????????¨?????????Arrays.sort(data, com);
		Comparator< Point2D > com = new Comparator< Point2D >() {
			public int compare(Point2D o1, Point2D o2) {
				if(o1.getX() < o2.getX()) return -1;
				else if(o1.getX() > o2.getX()) return 1;
				else if(o1.getY() < o2.getY()) return -1;
				else if(o1.getY() > o2.getY()) return 1;
				else return 0;
			} 
		};
		
		int ccw (Line2D l,Point2D p){
			return l.relativeCCW(p);
		}
		
		void doIt() {
			int ans = 0;
			String str[] = sc.nextLine().split(",");
			Point2D.Double a[] = new Point2D.Double [4];
			for(int i = 0;i < 4;i++){
				a[i] = new Point2D.Double(Double.parseDouble(str[i*2]),Double.parseDouble(str[i*2+1]));
			}
			Line2D.Double b[] = new Line2D.Double [4];
			for(int i = 0;i < 4;i++){
				b[i] = new Line2D.Double(a[i].getX(),a[i].getY(), a[(i+1)%4].getX(), a[(i+1)%4].getY());
				ans = ans + ccw(b[i],a[(i+2)%4]);
			}
			if(ans == 4 || ans == -4)System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 17192
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using std::cin;
using std::cout;
using std::vector;
using std::sort;

int main(){
    long long int n,k,ans=0;
    cin>>n>>k;
    if(n<=k){
        cout << 0 << '\n';
    }else{
        vector<int> hs;
        for(int i = 0;i<n;++i){
            int tmp;
            cin>>tmp;
            hs.push_back(tmp);
        }
        sort(hs.begin(),hs.end(),std::greater<int>());
        int start = 1;
        for(auto h:hs){
            if(start <= k){
                start++;
                continue;
            }
            ans += h;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 1400
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main implements Runnable {
	int N,M;
	char[] a,b;
	int[][] dp;

	public void solve() {
		a = next().toCharArray();
		b = next().toCharArray();

		N = a.length;
		M = b.length;

		dp = new int[N+1][M+1];

		for(int i = 0;i < M+1;i++){
			dp[0][i] = i;
		}

		for(int i = 0;i < N+1;i++){
			dp[i][0] = i;
		}

		for(int i = 1;i < N+1;i++){
			for(int j = 1;j < M+1;j++){
				int min = Math.min(dp[i-1][j]+1,dp[i][j-1]+1);
				if(a[i-1] == b[j-1]){
					min = Math.min(min, dp[i-1][j-1]);
				}else{
					min = Math.min(min, dp[i-1][j-1]+1);
				}
				dp[i][j] = min;
			}
		}

		out.println(dp[N][M]);

	}

	public static void main(String[] args) {
		new Thread(null, new Main(), "", 32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

Measured memory_bytes: 29104
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = 5e15;

ll solve() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll d = (B - A);
    if(d % 2 == 0) return d / 2;
    ll left = (A - 1);
    ll right = (N - B);
    return min(left + 1 + (d - 1) / 2,
               right + 1 + (d - 1) / 2);
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()

s_len = len(s)

for i in range(1, int(s_len/2)+1):
    s = s[:-2]
    half = int(len(s)/2)
    s_mae = s[:half]
    s_ato = s[half:]
    if s_mae == s_ato:
        break

print(len(s))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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



	int N,K;
	cin >> N >> K;

	int kotae = 1000000000;
	int doko = 1 << N;
	rep(i, doko) {
		int A = 1;
		int kari = i;
		rep(ii, N) {
			if (kari % 2) A *= 2;
			else A += K;
			kari /= 2;
		}
		kotae = min(kotae, A);

	}
	
	co(kotae);
	Would you please return 0;
}

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

int judge(int amari[], int n, int x){
  int a = 0;
  int i = 0;
  while(amari[i] != -1){
    if(amari[i] == x){
      a = 1;
      break;
    }
    i++;
  }
  return 0;
}

int main() {
  int K;
  cin >> K;
  int ans = -1;
  int x = 7;
  int amari[K+1];
  for(int i = 0; i < K+1; i++){
    amari[i] = -1;
  }
  for(int i=0; i < K; i++){
    x = x % K;
    if(x == 0){
      ans = i+1;
      break;
    }
    else if(judge(amari, K, x) == 1){
      ans = -1;
      break;
    }
    x = x*10 + 7;
    //cout << x << endl;
  }

  cout << ans << endl;

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

  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Measured memory_bytes: 7468
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
        int numA = int.Parse(input[0]);
      	int numB = int.Parse(input[1]);
      
      	string outStr = "No";
		if(numB % 2 == 0)
        {
          	for(int i = 0; i <= numA; i++)
            {
             	int kame = (numA - i) * 4;
              	int turu = i * 2;
              	if(kame + turu == numB)
                {
                 	outStr = "Yes";
                  	break;
                }
            }
        }
      	else
        {
         	outStr = "No";
        }
      	Console.WriteLine(outStr);
	}
}

Measured memory_bytes: 27456
#include<iostream>
using namespace std;
int main()
{
    int r;
    cin>>r;
    if(r<1200)
    {
        cout<<"ABC";
    }
    else if(r<2800)
    {
        cout<<"ARC";
    }
   else
   {
       cout<<"AGC";
   }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,M;
long long ans;
int a[111111];
struct PCSZ {
  // assumption: every root node points itself.
  struct node_t {
    int parent;
    int size;
    node_t() : size(1) {}
  };
  vector<node_t> nodes;

  PCSZ() { }
  PCSZ(int size) : nodes(size) {
    for (int i = 0; i < size; i++) {
      nodes[i].parent = i;
    }
  }

  // add more nodes
  void expand(int count) {
    int oldsize = nodes.size();
    nodes.resize(oldsize + count);
    for (int i = oldsize; i < oldsize + count; i++) {
      nodes[i].parent = i;
    }
  }

  void clear() {
    nodes.clear();
  }

  // find root node
  int find(int index) {
    int root = index;
    while (root != nodes[root].parent) {
      root = nodes[root].parent;
    }
    while (root != nodes[index].parent) {
      int next = nodes[index].parent;
      nodes[index].parent = root;
      index = next;
    }
    return root;
  }

  // true if merge was successful
  bool merge(int first, int second) {
    int r1 = find(first);
    int r2 = find(second);
    if (r1 == r2) {
      return false;
    }
    if (nodes[r1].size < nodes[r2].size) {
      // careful, first and second not swapped
      swap(r1, r2);
    }
    nodes[r1].size += nodes[r2].size;
    nodes[r2].parent = r1;
    return true;
  }

  int group_size(int index) {
    return nodes[find(index)].size;
  }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N>>M;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        a[i]=--x;
    }
    PCSZ uf(N);
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        uf.merge(x,y);
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        if(uf.find(i)==uf.find(a[i])){
            cnt++;
        }
    }
    cout<<cnt<<'\n';
    return 0;
}


Measured memory_bytes: 1408
def main():

  N, M, C = map(int, input().split(' '))
  Bs = input().split(' ')
  As = []
  for _ in range(N):
    As.append(input().split(' '))

  # print('----------')
  # print(N, M, C)
  # print(Bs)
  # print(As)

  result = 0
  for A in As:
    tmp = 0
    for a, b in zip(A, Bs):
      tmp = tmp + int(a) * int(b)
    tmp += int(C)

    if tmp > 0:
      result += 1

  print(result)


main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a[6] = {};
    bool check = false;
    for (int i = 0; i<6; i++){
        cin >> a[i];
    }
    
    for (int i=0;i<4;i++){
        for(int j=i+1;j<5;j++){
/*            cout <<"i" << i <<"j" <<j << endl;
            cout <<"ai " << a[i] << " a[j] " << a[j] <<endl;*/
            if( (a[j]-a[i]) > a[5]){
                check = true;
            }
        }
    }
    
    if (check == true) {
        cout << ":(";
    } else {
        cout << "Yay!";
    }
}

Measured memory_bytes: 256
import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}




func disco2020a() -> Int{
    let XY = readLine()!.split(separator: " ").map{Int($0)!}
    let X = XY[0]
    let Y = XY[1]
    let M:[Int] = [300000, 200000,100000]
    var ans = 0
    if X < 4 {ans += M[X-1]}
    if Y < 4 {ans += M[Y-1]}
    if (X == 1 && Y == 1){
        ans += 400000
    }
    return ans
}


print(disco2020a())


Measured memory_bytes: 13648
n, m = map(int, input().split())
a = list(map(int, input().split()))
threshold = 0
for ai in a:
  threshold += ai
threshold /= (4 * m)
a.sort(reverse=True)
tot = 0
for i in range(m):
  if a[i] < threshold:
    print('No')
    break
  if i == m - 1:
    print('Yes')
    break

Measured memory_bytes: 9088
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;


signed main(){
    ll n,ans = 0;
    cin >> n;
    ll a[n],b[n];
    
    P d[n];
    rep(i,0,n){
        cin >> a[i] >> b[i];
        d[i] = P(a[i]+b[i],i);
        ans -= b[i];
    }

    sort(d,d+n,greater<P>());

    rep(i,0,n){
        ans += d[i].fs ;
        i++;
    }

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


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

int main(){
    int N;
    cin >> N;
    vector<int> d(N,0);

    for (int i = 0; i < N;i++)
        cin >> d[i];

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

    int ans = 0;
    int t = N / 2 - 1;
    if(d[t] == d[t+1]){
        ans = 0;
    }else{
        ans = d[t + 1] - d[t];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main () {
  int n, l;
  cin >> n >> l;
  int sum = 0, mi = inf, eat = inf;
  rep1 (i, n) {
    sum += l + i - 1;
    if (mi > abs(l + i - 1)) {
      mi = abs(l + i - 1);
      eat = l + i - 1;
    }
  }
  cout << sum - eat << endl;
    
}


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

int main(void) {
    ll X,Y;
    ll tmp;
    cin >> X >> Y;
    tmp = X;
    int ans = 0;
    while (tmp <= Y) {
        ans++;
        tmp*=2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

template<typename V, typename W>
struct bellman_ford_result {
	bool has_negative_loop;
	std::vector<W> distance; // 距離
	std::vector<V> prev; // 「前」の頂点
};

/**
 * ベルマンフォード法により最短経路を求める
 *
 * @param edges 辺集合表現による辺の集合
 * @param start 始点
 * @param num 頂点の数
 * @param goal ある終点への経路だけが求まればいい場合はその終点を指定する。
 *             この場合、その終点に到達できない頂点への経路に減少閉路があっても関知しない。
 *             指定を省略した場合、全ての頂点への最短経路を求め、どこかに減少閉路があると中断される。
 *             なお、指定した場合の方が計算に時間がかかる。
 */
template<typename V, typename W>
bellman_ford_result<V, W> bellman_ford(const std::vector<std::tuple<V, V, W>>& edges, V start, V num, V goal = -1)
{
	std::vector<W> distance(num);
	std::vector<V> prev(num);
	std::fill(distance.begin(), distance.end(), std::numeric_limits<W>::max()/2);
	distance[start] = 0;
	prev[start] = start;

	for (int i = 0; i < (goal == -1 ? num : num * 2); ++i) {
		for (const auto& edge : edges) {
			auto& u = std::get<0>(edge);
			auto& v = std::get<1>(edge);
			auto& w = std::get<2>(edge);
			if (distance[v] > distance[u] + w) {
				distance[v] = distance[u] + w;
				prev[v] = u;
				if (goal == -1) {
					if (i == num - 1) {
						return { true, distance, prev };
					}
				} else {
					if (i >= num - 1 && v == goal) {
						return { true, distance, prev };
					}
				}
			}
		}
	}

	return { false, distance, prev };
}

int main()
{
	// ABC137

	long N, M, P;
	std::vector<std::tuple<long, long, long>> edges;

	std::cin >> N >> M >> P;
	edges.resize(N);
	for (int i = 0; i < M; ++i) {
		long a, b, c;
		std::cin >> a >> b >> c;
		edges.emplace_back(a-1, b-1, c);
	}

	auto bf_edges = edges;
	for (auto& e : bf_edges) {
		std::get<2>(e) = P-std::get<2>(e);
	}

	auto result = bellman_ford(bf_edges, (long)0, N, N-1);
	if (result.has_negative_loop) {
		std::cout << "-1\n";
	} else {
		std::cout << std::max(0L, -result.distance[N-1]) << "\n";
	}
}


Measured memory_bytes: 848
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;


int main(int argc, char const *argv[])
{
    map<int,int> a;
    for (size_t i = 0; i < 6; i++)
    {
        int temp;
        cin>>temp;
        a[temp]++;
    }
    int first=0;
    int second=0;
    int muri=0;
for(int i=1;i<5;i++){
    if(a[i]==1){
        first++;
    }else if(a[i]==2){
        second++;
    }else{
        muri++;
    }
}
if(first==2&&second==2&&muri==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;

  vector<int> acc;
  acc.push_back(0);

  int j = 1;
  int bt = 1;
  int cnt = 0;
  rep(i, s.size()) {
    if(s[i] != (char)(bt + '0')) {
      acc.push_back(cnt);
      j++;
      bt ^= 1;
    }
    ++cnt;
  }
  acc.push_back(cnt);
  if(!bt) acc.push_back(cnt);

  int m = acc.size();
  if(k >= m / 2) {
    cout << n << endl;
    return 0;
  }

  int ans = 0;
  for(int l = 1, r = k; r < m / 2; l++, r++) {
    ans = max(ans, acc[2 * r + 1] - acc[2 * l - 2]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1020
N,T=map(int,input().split());AB=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*T
AB.sort()
m=0
for a,b in AB:
  m=max(m,dp[-1]+b)
  for j in range(T-1,a-1,-1):
    dp[j] = max(dp[j],dp[j-a]+b)

print(m)


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

ans = 0
for i in range(n):
    x = c
    for j in range(m):
        x += a[i][j] * b[j]
    if x > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		sc.close();
		n--;
		StringBuilder sb = new StringBuilder();
		while(n>=26) {
			sb.insert(0, (char)('a'+n%26));
//		out.println(sb);
			n/=26;
			n--;
		}
		sb.insert(0, (char)('a'+n));
		out.println(sb);
	}
}


Measured memory_bytes: 26984
#include<cstdio>
#include<iostream>
#include<cstring>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;

inline ll read() { 
	ll s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 1005, p = 1e9+7;
struct node{ 
	ll f[3][3];
	node() { memset(f,0,sizeof(f)); }
} a, b; 

inline node operator * (const node&a,const node&b) { 
	node c;
	rep(i,1,2) { 
		rep(j,1,2) { 
			rep(k,1,2) c.f[i][j] += a.f[i][k] * b.f[k][j];
			c.f[i][j] %= p;
		}
	}
	return c;
}

inline ll Pow(ll x,ll t) { 
	ll ret = 1;
	while( t ) {
		if( t & 1 ) ret = ret * x % p;
		x = x * x % p, t >>= 1;
	} return ret; 
}

char c[N][N];

int main() { 
//	freopen("in.txt","r",stdin);
	int n = read(), m = read(), num = 0; ll K = read();
	rep(i,1,n) scanf("%s",c[i]+1);
	if( K == 0 || K == 1 ) return puts("1"), 0; 
	int f1 = 0, f2 = 0;
	rep(i,1,n) { 
		if( c[i][1] == '#' && c[i][m] == '#' ) f1++;
	}
	rep(i,1,m) { 
		if( c[1][i] == '#' && c[n][i] == '#' ) f2++;
	}
	if( f1 && f2 ) return puts("1"), 0;
	rep(i,1,n) rep(j,1,m) if( c[i][j] == '#' ) num++;
	if( !f1 && !f2 ) return printf("%lld\n", Pow(num,K-1)), 0;
	int z = 0;
	if( f1 ) { 
		rep(i,1,n) { 
			rep(j,2,m) if( c[i][j-1] == '#' && c[i][j] == '#' ) z++;
		}
	} else { 
		rep(i,2,n) { 
			rep(j,1,m) if( c[i-1][j] == '#' && c[i][j] == '#' ) z++;
		}
	}
	a.f[1][1] = num, a.f[2][1] = p - z, a.f[2][2] = f1 + f2;
	b = a, K -= 2;
	while( K ) {
		if( K & 1 ) b = b * a;
		a = a * a, K >>= 1;
	} 
	cout<<(b.f[1][1] + b.f[2][1]) % p<<endl;
}

Measured memory_bytes: 1280
/*
*  author: i_64 "Mrunal Ahire"
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int            long long
#define double         long double
#define endl           '\n'
#define x              first
#define y              second
#define remove         erase
#define pb             push_back
#define mod1           1000000007
#define mod2           998244353
#define xrange(i,s,n)  for(int i=s;i<n;i++)
#define yrange(i,n,s)  for(int i=n;i>=s;i--)
#define deb(x)         cerr<<'\t'<<#x<<" is "<<(x)<<endl
#define usefile        freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define debvec(v)      cerr<<#v<<" is [ ";for(auto el:v)cerr<<el<<" ";cerr<<"]\n";
#define debmap(m)      cerr<<#m<<" is [ ";for(auto p:m)cerr<<"("<<p.x<<","<<p.y<<") ";cerr<<"]\n";
#define io             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tezz           int32_t main(){io;solve();return 0;}
#define tezzn          int32_t main(){io;int32_t t;cin>>t;while(t--)solve();return 0;}
using namespace std;
using namespace __gnu_pbds;
// . . . S O L U T I O N . . . B E G I N S . . . F R O M . . . H E R E . . .

int a, b;

void solve () {
	cin >> a >> b;
	cout << (a * b) << endl;
}
tezz

Measured memory_bytes: 3640