akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <fstream>
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ; 
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
#define endl '\n'
typedef long long ll ;
typedef unsigned long long ull ; 
typedef long double ld ; 
using namespace std ;
const int N = 1e2+100 , MX = 1e5+100 ; 
const ll mod = 1e9 + 7  ;


ll n ,tot , W[N] , val[N] , dp[N][MX+5]; 


int _3102_ {
    Gamed
    cin >> n >> tot ; 
    for ( int i = 1 ; i <= n ; i ++){
        cin >> W[i] >> val[i] ; 
    }
    for ( int i = 0 ; i <= n ; i ++){
        for ( int j = 1 ; j <= MX ; j ++){
            dp[i][j] = 1e18 ; 
        }
    }
    for ( int i = 1 ; i <= n ; i ++){
        for ( int j = 1 ; j <= MX ; j ++){
            // leave 
            dp[i][j] = dp[i-1][j]  ;
            // minimizing between take or leave 
            if ( j >= val[i]){
                dp[i][j] = min ( dp[i][j] , dp[i-1][j-val[i]] + W[i]) ;
            }
        }
    }
    ll ans = 0 ; 
    for ( int i = 0 ; i <= MX ; i++){
        if ( dp[n][i] <= tot ) ans = max ( ans , ll(i) ) ; 
    }
    cout << ans <<endl ; 
    return 0;
}

Measured memory_bytes: 80128
c = [list(map(int, input().split())) for i in range(3)]

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            if (c[0][0] - a1 == c[1][0] - a2 == c[2][0] - a3) and (c[0][1] - a1 == c[1][1] - a2 == c[2][1] - a3) and (c[0][2] - a1 == c[1][2] - a2 == c[2][2] - a3):
                print("Yes")
                exit()
else:
    print("No")


Measured memory_bytes: 40940
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int N;
string S;

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

    int cnte = 0;
    rep(i, 0, N)
        if (S[i] == 'E')
            cnte++;

    int ans = 300010;
    int cntw = 0;
    rep(i, 0, N) {
        if (S[i] == 'W') {
            ans = min(ans, cnte + cntw);
            cntw++;
        }
        if (S[i] == 'E') {
            cnte--;
            ans = min(ans, cnte + cntw);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 832
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const long double eps=1e-10;
int n,m,a[200010];
bool check(long double limit)
{
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=ceil(a[i]/limit)-1;
		if(ans>m)return false;
	}return true;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    n=read(),m=read();int mx=0;
    for(int i=1;i<=n;i++)a[i]=read(),mx=max(mx,a[i]);
    long double l=0,r=mx,ans=mx;
    while(r-l>=eps)
    {
    	long double mid=(l+r)/2.0;
    	if(check(mid)==true)ans=mid,r=mid;
    	else l=mid;
    }printf("%d\n",(int)ceil(ans));
    return 0;
}

Measured memory_bytes: 2300
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


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


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()
a_array = na()
ans = 0
for i in range(N):
    if i % 2 == 0 and a_array[i] % 2 == 1:
        ans += 1


print(ans)


Measured memory_bytes: 61768
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
using namespace std;

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

    cout << 700 + 100 * count(S.begin(), S.end(), 'o') << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
  int n;
  cin>>n;
  vector<int> a(n);
  REP(i,0,n-1) {
    cin >> a[i];
  }
  ll ans = 0;
  ll sum = 0;
  REPN(i,n-1,0) {
    ans = (ans + a[i] * sum) % mod;
    sum = (sum + a[i]) % mod;
  }
  cout << ans;
}

int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3932
#include <cstdio>
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
const int maxn = 100 + 5;
char a[maxn][maxn];
int main(){
   int n,m;
   scanf("%d%d",&n,&m);
   n--;m--;
   for (int i = 0; i < 100; i++){
     for (int j = 0; j < 50; j++){
          a[i][j] = '.';
     }
   }
   for (int i = 0; i < 100; i++){
     for (int j = 50; j < 100; j++){
         a[i][j] = '#';
     }
   }
   int flag = 0;
   int flag2 = 0;
   for (int i = 99; i >= 0; i-=2){
       for (int j = 99; j >= 51; j -= 2){
           if (!n) {
            flag2 = 1;
            break;
           }
           a[i][j] = '.';
           //cout<<n<<" "<<i<<" "<<j<<endl;
           n--;
       }
       if (flag2) break;
       flag ^= 1;
   }
   flag2 = 0;
   for (int i = 99; i >= 0; i-=2){
      for (int j = 48; j >= 0; j -= 2){
          if (!m)
          {
              flag2 = 1;
              break;
          }
          a[i][j] = '#';
          m--;
      }
      if (flag2) break;
      flag ^= 1;
   }
   cout<<"100 100"<<endl;
   for (int i = 0; i < 100; i++){
     for (int j = 0; j < 100; j++){
        printf("%c",a[i][j]);
     }
     printf("\n");
   }
} 

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

if b.sum > a.sum then
    puts -1
    exit
end

plus = []
minus = []
n.times do |i|
    tmp = a[i] - b[i]
    if tmp > 0 then
        plus << tmp
    elsif tmp < 0 then
        minus << tmp
    end
end

if minus.empty? then
    puts 0
    exit
end

plus.sort!
minus.sort!

ans = 0
tmp = 0

until minus.empty? && tmp >= 0
    if tmp == 0 then
        tmp = minus.shift + plus.pop
        ans += 2
    elsif tmp > 0 then
        tmp += minus.shift
        ans += 1
    else
        tmp += plus.pop
        ans += 1
    end
end

puts ans

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

using namespace std;

string c[1111];
inline void A(int y, int x, int &a) {
	if (a-- > 0) {
		c[y][x] = '<';
		c[y][x + 1] = '>';
	}
}
inline void B(int y, int x, int &b) {
	if (b-- > 0) {
		c[y][x] = '^';
		c[y + 1][x] = 'v';
	}
}

int main()
{
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	if ((a + b) * 2 > n*m || (a + b) * 2 == n * m&&a % 2 + n % 2 && b % 2 + m % 2 || a > m / 2 * n || b > n / 2 * m) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++)
		c[i].insert(0, m, '.');
	if (n % 2) {
		for (int i = 0; i < m - 1; i += 2)
			A(n - 1, i, a);
	}
	if (m % 2) {
		for (int i = 0; i < n - 1; i += 2)
			B(i, m - 1, b);
	}
	if (n % 2 && m % 2 && a % 2) {
		b++;
		c[n - 3][m - 1] = c[n - 2][m - 1] = '.';
		A(n - 3, m - 2, a);
		B(n - 3, m - 3, b);
		B(n - 2, m - 1, b);
	}
	for (int i = 0; i < n - 1; i += 2) {
		for (int j = 0; j < m - 1; j += 2) {
			if (a > 0) {
				A(i, j, a);
				A(i + 1, j, a);
			}
			else {
				B(i, j, b);
				B(i, j + 1, b);
			}
		}
	}
	for (int i = 0; i < n; i++)
		cout << c[i] << '\n';
	cout << flush;
	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x;
    cin >> x;
    while (1) {
        bool ok = true;
        for (int i=2; i<x; i++) {
            if (x%i==0) {
                ok = false;
                break;
            }
        }
        if (ok) break;
        x++;
    }
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll a,b,c,k;
//ld ;
//string s;
 
int main() {
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if(k<=a){
    ans = k;
  }else if(k<=a+b){
    ans = a;
  }else{
    ans = a-(k-a-b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s)
{
  queue<int> q;
  q.push(s);
  for (int i = 0; i < n; i++)
  {
    d[i] = INFTY;
  }
  d[s] = 0;

  int u;
  while (!q.empty())
  {
    u = q.front();
    q.pop();
    for (int v = 0; v < n; v++)
    {
      if (M[u][v] == 0)
      {
        // 繋がってない
        continue;
      }
      if (d[v] != INFTY)
      {
        // 訪問済
        continue;
      }
      d[v] = d[u] + 1; // 一つ先
      q.push(v);
    }
  }

  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
  }
}

int main()
{
  int u, k, v;

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

  for (int i = 0; i < n; i++)
  {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++)
    {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
int main(){
	int n=read();
	cout<<(n-1)/2;
	return 0;
}


Measured memory_bytes: 3624
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/STACK: 20000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec vector
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){IOS;
    ll k,n;cin>>k>>n;
    vec<ll> v(n); for(auto&it:v)cin>>it;
    vec<ll> diffs;
    for(int i=1;i<n;i++) diffs.push_back(v[i]-v[i-1]);
    diffs.push_back( k-v.back() + v[0] );
    sort(all(diffs));
    ll res = 0;
    for(int i=0;i<n-1;i++) res+=diffs[i];
    cout<<res<<endl;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,0,n) cin>>a[i];
    int dp[k+1];
    rep(i,0,k+1) dp[i]=0;
    rep(i,1,k+1){
        rep(j,0,n){
            if(i==a[j]){
                dp[i]=1;
                break;
            }
            else if(i>a[j] && dp[i-a[j]]==0) dp[i]=1;
        }
    }
    if(dp[k]) cout<<"First";
    else cout<<"Second";


}

Measured memory_bytes: 1024
a,b,c=map(int,input().split())
x=max(a,b,c)
y=min(a,b,c)
z=a+b+c-x-y
if (z-y)%2==0:
  print(x-z+(z-y)//2)
else:
  print(x-z+1+(z-y+1)//2)

Measured memory_bytes: 9208
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> lens;
	int current = s[0]-'0';
	int current_start = 0;
	if(s[0]=='0') lens.push_back(0);
	FOR(i,1,n-1){
		int buf = s[i]-'0';
		if(current!=buf){
			lens.push_back(i-current_start);
			current_start = i;
			current = buf;
		}
	}
	lens.push_back(n-current_start);
	if(s[n-1]=='0') lens.push_back(0);

	int lsize = lens.size();
//	REP(i,lsize){
//		errln(lens[i]);
//	}

	int zcnt = (lsize-1)/2;
	if(zcnt <= k){
		int sum = 0;
		REP(i,lsize){
			sum += lens[i];
		}
		println(sum);
		return 0;
	}else{
		int sum = 0;
		REP(i,k*2+1){
			sum += lens[i];
		}
		int ret = sum;
//		errln(sum);
		REP(i,zcnt-k){
			sum -= (lens[i*2]+lens[i*2+1]);
			sum += (lens[(i+k)*2+1]+lens[(i+k)*2+2]);
//			errln(sum);
			ret = max(ret,sum);
		}
		println(ret);
	}


	return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
 
// auto start = high_resolution_clock::now(); 
// auto stop = high_resolution_clock::now(); 
// auto duration = duration_cast<microseconds>(stop - start); 
 
// cout << duration.count() << endl; 
 bool sortbysecdesc(const pair<ll,ll> &a, 
                   const pair<ll,ll> &b) 
{ 
       return a.second>b.second; 
}

int main()
{
 
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
// int t;
// cin >> t;
// while(t--){

// }

    int n;
    cin >> n;
    int arr[n];
    fo(i,0,n)cin >> arr[i];
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    fo(i,2,n){
    	dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout << dp[n-1] << endl;
return 0;
}


Measured memory_bytes: 1408
#ceilevenoddformula
import math
import bisect
import copy
import time
from collections import Counter
#map(int,input().split())
#int(x) for x in input().split()
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
x=[]
for i in range(n-k):
	if l[i]<l[i+k]:
		print('Yes')
	else:
		print('No')
































Measured memory_bytes: 94528
#include <stdio.h>

int main()
{
int s, sn;

scanf("%d", &s);

sn = s/1000000000 +
s%1000000000/100000000 +
s%100000000/10000000 +
s%10000000/1000000 +
s%1000000/100000 +
s%100000/10000 +
s%10000/1000 +
s%1000/100 +
s%100/10 +
s%10;

if((s%sn)==0) printf("Yes");
else printf("No");

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int w,d; cin >> w >> d;
		if(w==0&&d==0)break;
		vector<int> h(w),hh(d);
		for(int i=0;i<w;i++){
			cin >> h[i];
		}
		map<int,int> mp;
		for(int j=0;j<d;j++){
			cin >> hh[j];
			mp[hh[j]]++;
		}
		int res=0;
		for(int i=0;i<w;i++){
			if(mp[h[i]]>0){
				mp[h[i]]--;
			}
			res+=h[i];
		}
		for(auto p:mp){
			res+=p.first*p.second;
		}
		printf("%d\n",res );
	}
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define scan(a) scanf("%d",&a)
#define scan2(a,b) scanf("%d %d",&a,&b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define print(x) printf("%d\n",x)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<pair<int,int> > vpii;
static const int INF = 0x3f3f3f3f;
static const ll INFL = 0x3f3f3f3f3f3f3f3fLL;


int main()
{
    int n;
    scan(n);
    int pt=0,px = 0,py = 0,flag = 0 ;
    for(int i=0;i<n;++i)
    {
        int t,x,y;
        scan3(t,x,y);
        if( flag == 0)
        {
            int delt = t - pt;
            if( delt < 0)
                flag = 1;
            int dis = abs(x-px)+abs(y-py);
            if( dis > delt )
                flag = 1;
            else if(delt > dis)
            {
                int tt = delt - dis ;
                if( tt%2  == 1)
                    flag = 1;
            }
        }
        pt = t;
        px = x;
        py = y;
    }
    if( flag == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
import Data.List
import Data.Maybe

solve :: Int -> Int -> String
solve a b
  | a > b = "Alice"
  | a < b = "Bob"
  | otherwise = "Draw"

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  let seq = [2..13] ++ [1]
  putStrLn $ solve (fromJust $ elemIndex a seq) (fromJust $ elemIndex b seq)

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAX=1e5+10;
const int INF=1e9+10;
int n,mw;
int w,v;
ll ans,dp[MAX];
int main(){
	cin>>n>>mw;
	for(int i=0;i<n;i++){
		cin>>w>>v;
		for(int j=mw-w;j>=0;j--){
			//cout<<j<<" "<<w<<" "<<j+w<<"\n";
			dp[j+w]=max(dp[j+w],dp[j]+v);
		}
		/*
		for(int j=0;j<=mw;j++){
			cout<<dp[j]<<" ";
		}cout<<"\n";
		*/
	}
	for(int i=0;i<=mw;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int N , M;
    cin >> N  >> M;
    int A[N][M];
    int K[N];

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

    map<int, int> mp;

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < K[i]; j++)
        {
            mp[A[i][j]]++; 
        }
    }

    int res = 0;
    for(auto m : mp)
    {
        if(m.second == N)
        {
            res++;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 200100

ll N,R,C;
vector<pair<ll,pi>> V;
ll a,b,c;
ll p[MAXN];
ll par(ll x){return (p[x] == x)?x:p[x]=par(p[x]);}
ll key[MAXN];
ll ans;

int main(){
	cin>>N>>R>>C;
	for (ll i=0;i<N;++i){
		cin>>a>>b>>c;
		V.pb(mp(c,mp(a,b)));
	}
	sort(ALL(V));
	reverse(ALL(V));
	for (ll i=1;i<=R+C;++i)p[i]=i;
	for (ll i=0;i<N;++i){
		pair<ll,pi> cur = V[i];
		a = cur.s.f;
		b = cur.s.s + R;
		a=par(a);b=par(b);
		// cout<<cur.f<<' '<<cur.s.f<<' '<<cur.s.s<<'\n';
		if (a==b){
			if (key[a])continue;
			ans += cur.f;
			key[a] = 1;
		}
		if (key[a] && key[b])continue;
		p[a]=b;
		key[b] = key[a] = key[a] | key[b]; // If either are already keychains then merged becomes keychain
		ans += cur.f;
	}
	cout<<ans;
}

Measured memory_bytes: 6256
N= int(input())
X = [list(map(int, input().split())) for _ in range(N)]
L = 3
dp = [[0 for _ in range(3)] for _ in range(N+1)]

dp[0] = [0,0,0]
for i in range(N):
  dp[i+1] = [max([dp[i][k] for k in range(L) if k != j]) + X[i][j] for j in range(L)]

print(max(dp[-1]))
  

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

const int M = 2e5 + 100;
vector<int> e[M];
int a[M], ans[M];
int b[M], len;

void dfs(int u, int pre) {
	int id = lower_bound(b, b + len, a[u]) - b;
	int del = -1;
	if (id != len) del = b[id];
	else ++len;
	b[id] = a[u];
	ans[u] = len;
	for (auto v : e[u]) {
		if (v != pre) {
			dfs(v, u);
		}
	}
	if (del == -1) --len;
	else b[id] = del;
}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v;
		--u, --v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(0, -1);
	for (int i = 0; i < n; i++) cout << ans[i] << "\n";
}

Measured memory_bytes: 30448
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace  std;
const int N=2e6+5;
#define INFTY (1<<30)
int h,a[N];
void maxheapify(int i){
    int l,r,largest;
    l=2*i;
    r=2*i+1;
    if(l<=h&&a[l]>a[i]) largest=l;
    else largest=i;
    if(r<=h&&a[r]>a[largest]) largest=r;
    if(largest!=i){
        swap(a[i],a[largest]);
        maxheapify(largest);
    }
}
int extract(){
    int maxv;
    if(h<1) return -INFTY;
    maxv=a[1];
    a[1]=a[h--];
    maxheapify(1);
    return maxv;
}
void increasekey(int i,int key){
    if(key<a[i]) return;
    a[i]=key;
    while(i>1&&a[i/2]<a[i]){
        swap(a[i],a[i/2]);
        i/=2;
    }
}
void insert(int key){
    h++;
    a[h]=-INFTY;
    increasekey(h, key);
}
int main(){
    int key;
    char com[10];
    while(1){
        scanf("%s",com);
        if(com[0]=='e'&&com[1]=='n') break;
        if(com[0]=='i'){
            scanf("%d",&key);
            insert(key);
        }
        else
            printf("%d\n",extract());
    }
    return 0;
}

Measured memory_bytes: 7092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  s += 'A';
  char c = s[0];
  rep(i, n+1) {
    if (s[i] != c) {
      ans++;
      c = s[i];
    }
  }

  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A%2==0 && A==B && B==C){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0; i<10000000; i++){
        if(A%2 || B%2 || C%2){
            cout << i << endl;
            return 0;
        }
        int tmp=0;
        tmp=A/2;
        A+=-A/2+C/2;
        C+=-C/2+B/2;
        B+=-B/2+tmp;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
struct st {
	int n;
	vi vec;
};
vector<st> num;
int dfs(int n) {
	if (num[n].vec.size() == 0)
		return 0;
	vi num2(num[n].vec.size());
	REP(i, num[n].vec.size()) {
		num2[i]=dfs(num[n].vec[i]);
	}
	SORT(num2);
	int ma = 0;
	REP(i, num2.size()) {
		ma = max(ma, num2[i]+ (int)num[n].vec.size()-i);
	}
	return ma;
}
int main() {
	int n;
	cin >> n;
	num.resize(n);
	REP(i, n - 1) {
		int a;
		cin >>a;
		num[a - 1].vec.push_back(i+1);
	}
	cout << dfs(0) << endl;
}

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

int s[200010][30];

int main()
{
    int n; cin>>n;
    vector<int> a(n); for(auto& e: a) cin>>e;

    for(int i=0; i<n; ++i)
        for(int j=0; j<30; ++j)
            s[i+1][j]=s[i][j]+((a[i]>>j)&1);

    int64_t res=0, L=0, R=1;
    while (L<=n) {
        bool ok=true;
        while (ok && R<=n) {
            for(int j=0; ok && j<21; ++j) if (s[R][j]-s[L][j]>1) ok=false;
            if (ok) {
                res+=R-L;
                ++R;
            }
        }
        ++L;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 24448
import qualified Data.Map as M
f::Int->Int->Int
f n m = m `mod` n 

f2::Int->Int->[Int]->M.Map Int Int->Int
f2 _ _ [] _=0
f2 m m2 (x:xs) ms=
                  let m3=(m+x) `mod` m2
                      --m4=(m+m2-(x `mod` m2)) `mod` m2
                      ms2=M.insertWith (+) m3 (-1) ms
                  in if M.member m ms
                  then 
                  let (Just t)=(M.lookup m ms)
                      t2=maximum (t:0:[])
                      --ms2=M.delete y2 ms
                  in t2+(f2 m3 m2 xs ms2)
                  else (f2 m3 m2 xs ms2)

main = do
       a<-getLine
       b<-getLine
       let (_:m:[])=(map read . words) a::[Int]
           xs=(map read . words ) b ::[Int]
           ys=(map (f m) $ scanl1 (+) xs)
           zs=zip ys [1,1..]
           ms=M.fromListWith (+) zs
       print $ f2 0 m xs ms

Measured memory_bytes: 54652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    string S;
    cin >> S;
    int cnt = 0;
    REP(i,S.size()-1){
        if(S[i] != S[i+1])cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
// include <isostream>
using namespace std;
#define _GLIBCXX_DEBUG /GCC環境下で[]による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); etc
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }

int main() {
int n,m;
cin>>n>>m;
#define setint set<int>
set<setint> road;
rep(i,m){
    int a,b;
    cin>>a>>b;
    set<int> s;
    s.insert(a);
    s.insert(b);
    road.insert(s);
}
vector<int> city_(n-1);
rep(i,n-1){
    city_.at(i)=i+1;
}
int sum=0;
do{
  vector<int>city(n);
  city.at(0)=0;
  rep(i,n-1){
    city.at(i+1)=city_.at(i);}
    rep(i,n-1){
        set<int>c;
        c.insert(city.at(i)+1);
        c.insert(city.at(i+1)+1);
        if(!road.count(c)){
           goto SKIP;
        }
    }
  sum+=1;
   SKIP:
   int p;
}while(next_permutation(city_.begin(),city_.end()));
cout<<sum<<endl;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

unsigned ll ggd(unsigned ll number1,unsigned ll number2){
    unsigned ll m = number1;
    unsigned ll n = number2;

    if(number2 > number1){
        m = number2;
        n = number1;
    }

    while(m != n){
        unsigned ll temp = n;
        n = m - n;
        m = temp;
    }

    return m;
}

unsigned ll lcm(unsigned ll number1,unsigned ll number2){
    return number1 * number2 / ggd(number1,number2);
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll int n;
    cin >> n;
    LP a[n];
    rep(i, n) cin >> a[i].second >> a[i].first;
    sort(a, a + n);
    int h = 0;
    ll time = 0;
    rep(i, n){
        if(time + a[i].second <= a[i].first) time += a[i].second;
        else h = 1;
    }
    if(h ==1) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, k;
  cin >> n >> k;
  vi w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];

  vector<vl> dp(n+1, vl(k+1));
  rep(i, n) {
    rep(j, k+1) {
      dp[i+1][j] = dp[i][j];
      if (j >= w[i]) {
        cmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
      }
    }
  }

  cout << dp[n][k] << endl;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,y;
	cin>>n>>y;
	if(y % 1000){
		printf("-1 -1 -1\n");
		return 0;
		}
	y /= 1000;
	for(int i = 0; i <= 20000; i++)
		for(int j = 0; j <= 20000; j++){
			if(i + 5 * j > y)
				break;
			else{
				int tot = (y - (i + 5 * j)) % 10;
				int ans = (y - (i + 5 * j)) / 10;
				if(!tot && i + j + ans == n){
                    printf("%d %d %d\n",ans,j,i);
					return 0;
					}
				}	
			}
	printf("-1 -1 -1\n");
	return 0;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define endl '\n'
using namespace std;
int main()
{
    int n,m,c;
    int b[21],a[21][21];
    cin>>n>>m>>c;
    for(int i = 1; i<=m; i++)
        cin>>b[i];
    int cnt = 0,sum = 0;
    for(int i = 1; i<=n; i++)
    {
        sum = c;
        for(int j = 1; j<=m; j++)
        {
            cin>>a[i][j];
            sum+=( a[i][j] * b[j] );
        }
        if(sum>0)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a;
	int b;
	cin>>a>>b;
if(a==0){
	cout<<"Zero";
}
else if(a>0&&b>0){
	cout<<"Positive";
}
else if(a<0&&b>=0){
	cout<<"Zero";
}
else{
	a*=-1;
	b*=-1;
	int k=b-a;
	k++;
	if(k%2==0){
		cout<<"Positive";
	}
	else{
		cout<<"Negative";
	}
}
		return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

//1950~

void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  cin >> a[0];

  ll ans = 0;
  ll sum = a[0];
  for(int i = 1; i < n; ++i)
  {
    cin >> a[i];
    if (a[i - 1] < a[i])
    {
      if (a[i - 1] > 0)
      {
        a[i] += sum % 2;
      }
      ans += sum / 2;
      sum = 0;
    }
    sum += a[i];
  }
  cout << ans + sum / 2;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3984
#include<stdio.h>
int main(){
	int n,H=0,t=0,sum=0;
	scanf("%d",&n);
	while(n){
		int h;
		scanf("%d",&h);
		if(H>=h){
			t++;
			if(t>sum) sum=t;
		}
		else if(H<h){
			t=0;
		}
		H=h;n--;
	}
	printf("%d",sum);
	return 0;
} 

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N;

int main() {
    cin >> N;

    ll ans = N * (N - 1) / 2;

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


Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==7&b==5&c==5) printf("YES\n");
	else if(a==5&b==7&c==5) printf("YES\n");
	else if(a==5&b==5&c==7) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  if(a < b){
    if((a+b)%2 == 0)
      cout << "Alice" << endl;
    else
      cout << "Borys" << endl;
  }
  else{
    if((a+b)%2 == 0)
      cout << "Borys" << endl;
    else
      cout << "Alice" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative

hour :: Int -> Int
hour s = div s 3600

minute :: Int ->Int
minute s = div (mod s 3600) 60

second :: Int ->Int
second s = s-(hour s)*3600-(minute s)*60

ans :: (Int,Int,Int)->String
ans (h,m,s)=(show h)++":"++(show m)++":"++(show s)

main :: IO()
main = do
    s<-(\x -> read x :: Int) <$> (getLine)
    putStrLn (ans (hour s,minute s,second s))


Measured memory_bytes: 3668
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
char in[20];
int main(){
	scanf("%s",in);
	for(int i=0;in[i];i++){
		if(in[i]==',')printf(" ");
		else printf("%c",in[i]);
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

int main(void)
{
  char  s[201];
  int  i, k;

  scanf("%s", s);

  k=strlen(s);
  for(k = k/2-1; k >= 1; k--){
    for(i = 0; i < k; i++){
      if(s[i] != s[i+k] ) break;
    }
    if( i == k ) break;
  }

  printf("%d\n", i*2);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, c, s, g;
int matrix[30][110][110];
int ps[100];
int qs[100][100];
int rs[100][100];
int cost[30][20100];

int main() {
  while (scanf("%d %d %d %d %d", &n, &m, &c, &s, &g), n) {
    s--; g--;
    MEMSET(matrix, 0x0f);
    REP(a, c) REP(i, n) { matrix[a][i][i] = 0; }
    REP(i, m) {
      int f, t, d, g;
      scanf("%d %d %d %d", &f, &t, &d, &g);
      f--; t--; g--;
      matrix[g][f][t] = matrix[g][t][f] = min(matrix[g][f][t], d);
    }
    REP(a, c) REP(k, n) REP(i, n) REP(j, n) {
      matrix[a][i][j] = min(matrix[a][i][j], matrix[a][i][k] + matrix[a][k][j]);
    }
    REP(i, c) { scanf("%d", &ps[i]); }
    REP(i, c) {
      REP(j, ps[i] - 1) {
        scanf("%d", &qs[i][j]);
      }
      qs[i][ps[i] - 1] = 1e+9;
      REP(j, ps[i]) {
        scanf("%d", &rs[i][j]);
      }
      cost[i][0] = 0;
      int index = 0;
      FOREQ(j, 1, 20010) {
        while (qs[i][index] < j) { index++; }
        cost[i][j] = cost[i][j - 1] + rs[i][index];
      }
    }
    REP(a, c) REP(i, n) REP(j, n) {
      if (matrix[a][i][j] == 0x0f0f0f0f) { continue; }
      matrix[a][i][j] = cost[a][matrix[a][i][j]];
    }
    REP(a, c) REP(i, n) REP(j, n) {
      matrix[0][i][j] = min(matrix[0][i][j], matrix[a][i][j]);
    }
    REP(k, n) REP(i, n) REP(j, n) {
      matrix[0][i][j] = min(matrix[0][i][j], matrix[0][i][k] + matrix[0][k][j]);
    }
    if (matrix[0][s][g] == 0x0f0f0f0f) {
      puts("-1");
    } else {
      printf("%d\n", matrix[0][s][g]);
    }
  }
}

Measured memory_bytes: 3896
#!/usr/bin/env python3

def inValidRegion(i,j,H,W):
    return i >= 0 and i < H and j >= 0 and j < W


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    H,W = map(int,input().split())
    Ch,Cw = map(int,input().split())
    Dh,Dw = map(int,input().split())
    S = []
    for i in range(H):
        S.append(list(input()))
    # print(S)
    R = []
    for i in range(H):
        R.append([])
        for j in range(W):
            R[i].append(-1 if S[i][j]=="#" else 0)
    currentId = 1
    for ii in range(H):
        for ij in range(W):
            if R[ii][ij] != 0:
                continue
            init = (ii,ij)
            c = set()
            c.add(init)
            while len(c) > 0:
                i,j = c.pop()
                R[i][j] = currentId
                if inValidRegion(i+1,j,H,W) and R[i+1][j] == 0:
                    c.add((i+1,j))
                if inValidRegion(i,j+1,H,W) and  R[i][j+1] == 0:
                    c.add((i,j+1))
                if inValidRegion(i-1,j,H,W) and R[i-1][j] == 0:
                    c.add((i-1,j))
                if inValidRegion(i,j-1,H,W) and  R[i][j-1] == 0:
                    c.add((i,j-1))
            currentId+=1
    # print(R)
    Connections = [set() for i in range(currentId)]
    Ca = R[Ch-1][Cw-1]
    Da = R[Dh-1][Dw-1]
    # print(Ca,Ch,Cw)
    # print(Da,Dh,Dw)
    if Ca == Da:
        print(0)
    else:
        for i in range(H):
            for j in range(W):
                a = R[i][j]
                if a == -1:
                    continue
                for k in range(-2,3):
                    for l in range(-2,3):
                        if inValidRegion(i+k,j+l,H,W):
                            a2 = R[i+k][j+l]
                            if a2 != a and a2 > 0:
                                Connections[a].add(a2)
                                Connections[a2].add(a)
        # print(Connections)
        reached = set([Ca])
        nextSet = set([Ca])
        warp = 0
        while len(nextSet) > 0:
            currentSet = nextSet
            nextSet = set()
            warp += 1
            while len(currentSet) > 0:
                current = currentSet.pop()
                for c in Connections[current]:
                    if c not in reached:
                        reached.add(c)
                        nextSet.add(c)
                    if c == Da:
                        print(warp)
                        return
        print(-1)

    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 185120
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    int H,W;
    cin >> H >> W;
    string S[50];
    for(int i=0; i<H; i++) cin >> S[i];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            int tmp = 0;
            if(i-1>=0 && S[i-1][j]=='#') tmp++;
            if(i-1>=0 && j-1>=0 && S[i-1][j-1]=='#') tmp++;
            if(i-1>=0 && j+1<W && S[i-1][j+1]=='#') tmp++;
            if(j-1>=0 && S[i][j-1]=='#') tmp++;
            if(j+1<W && S[i][j+1]=='#') tmp++;
            if(i+1<H && S[i+1][j]=='#') tmp++;
            if(i+1<H && j-1>=0 && S[i+1][j-1]=='#') tmp++;
            if(i+1<H && j+1<W && S[i+1][j+1]=='#') tmp++;
            S[i][j] = '0' + tmp;
        }
    }
    for(int i=0; i<H; i++) cout << S[i] << endl;
    
    return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
int main(){
	//soal A
	int N,K;
	scanf("%d%d", &N,&K);
	int nilai[N];
	for(int i=0;i<N;i++){
		scanf("%d", &nilai[i]);
	}
	
	for(int i=0;i<N-K;i++){
		if(nilai[i]<nilai[i+K]){
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 2392
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    REP(i,K) {
        int d; cin >> d;
        REP(j,d) {
            int a; cin >> a;
            a--;
            v[a]++;
        }
    }

    int ans =0;
    REP(i,N) {
        if (v[i] == 0) ans++;
    }

    cout << ans << '\n';


    return 0;
}

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

struct point{
    int x,y,cnt;
};

char maze[60][60]={0};
int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
int checked[60][60] = {0};

int main(){
    int w,h;
    while(scanf("%d %d",&w,&h),w!=0||h!=0){
        for(int i=0;i<2*h-1;++i){
            for(int j=0;j<2*w-1;++j){
                checked[i][j] = INT_MAX;
                maze[i][j] = 0;
            }
        }
        maze[0][0] = 'S';
        maze[2*(h-1)][2*(w-1)] = 'G';

        for(int i=0;i<2*h-1;++i){
            if((i&1) == 0){
                for(int j=0;j<w-1;++j){
                    int c;
                    scanf(" %d",&c);
                    if(c == 1)maze[i][2*j+1] = '#';
                }
            }else{
                for(int j=0;j<w;++j){
                    int c;
                    scanf("%d ",&c);
                    if(c == 1)maze[i][2*j] = '#';
                }
            }
        }

        queue<point> que;
        checked[0][0] = 0;
        que.push((point){0,0,1});
        bool flag = false;
        while(!que.empty()){
            point now = que.front(); que.pop();
            if(maze[now.y][now.x] == 'G'){
                printf("%d\n",now.cnt);
                flag = true;
                break;
            }
            for(int i=0;i<4;++i){
                if(now.x+dx[i]*2 >= 0 && now.x+dx[i]*2 < 2*w-1 && now.y+dy[i]*2 >= 0 && now.y+dy[i]*2 < 2*h-1 \
                    && maze[now.y+dy[i]][now.x+dx[i]] != '#'){
                    if(now.cnt+1 < checked[now.y+dy[i]*2][now.x+dx[i]*2]){
                        que.push((point){now.x+dx[i]*2,now.y+dy[i]*2,now.cnt+1});
                        checked[now.y+dy[i]*2][now.x+dx[i]*2] = now.cnt + 1;
                    }
                }
            }
        }
        if(!flag)printf("0\n");
    }

    return 0;
}


Measured memory_bytes: 3272
#include <iostream>
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int ans1 = 10 * A + B + C;
  int ans2 = A + 10 * B + C;
  int ans3 = A + B + 10 * C;
  cout << max(ans1, max(ans2, ans3)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
	int sets;
	char input1[500], input2[500], out[500];
	int i1, i2, o, carry;
	int ic1, ic2;
	int i;

	cin >> sets;
	for(i=0;i<sets;i++) {
		scanf("%s", input1);
		for(i1=0;input1[i1] != '\0';i1++);
		scanf("%s", input2);
		for(i2=0;input2[i2] != '\0';i2++);
		i1--;i2--;o=0;carry=0;
		while(i1>=0 || i2>=0 || carry) {
			if(o > 80) { break; }
			if(i1>=0) { ic1 = input1[i1]-'0'; i1--; } else { ic1 = 0; }
			if(i2>=0) { ic2 = input2[i2]-'0'; i2--; } else { ic2 = 0; }
			if( ic1+ic2+carry < 10 ) {
				out[o] = ic1+ic2+carry+'0';
				carry = 0;
			} else {
				out[o] = ic1+ic2+carry-10+'0';
				carry = 1;
			}
			o++;
		}
		if(o > 80) {
			printf("overflow\n");
		}
		else {
			for(o--;o>=0;o--) {
				printf("%c", out[o]);
			}
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main (){
	int n;
	long long int total = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		if(i%3 != 0 && i%5 != 0){
			total += i;
		}
	}
	printf("%lld", total);
	return 0;
}


Measured memory_bytes: 1728