akhauriyash/Code-Regression huggingface dataset:
//17:33
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
ll max(ll a, ll b){return(a>b)?a:b;}
ll min(ll a, ll b){return(a<b)?a:b;}
ll abs(ll a){return(a<0)?-a:a;}

ll gcd(ll a, ll b){
        if(b > a){
                ll tmp = b;
                b = a;
                a = tmp;
        }
        if(b == 0) return a;
        else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
        ll gcdi = gcd(a,b);
        return a/gcdi*(b);
}


int t[200001];
int main(){
        ll N,T;
        scanf("%lld %lld",&N,&T);

        for(int i = 0; i < N; i++){
                scanf("%d",t+i);
        }
        int before = t[N-1];
        int total = T;
        for(int i = N-2; i >= 0; i--){
                total += min(before-t[i],T);
                before = t[i];
        }
        printf("%d\n",total);
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <functional>

using namespace std;

int main(void) {
	int c[3];
	cin >> c[0] >> c[1] >> c[2];
	sort(c, c + 3);
	cout << ((c[0] + c[1] == c[2]) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var abt = Input.ar;
        WriteLine(abt[2] / abt[0] * abt[1]);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define rep1(i,n) for(in6 i = 1; i < (in6)(n); i++)
#define repc(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 200000000

int main() {
  kyun;
  int n,m;
  cin >> n >> m;
  vi data(m);
  rep(i,m) cin >> data[i];
  sort(all(data));
  vi dp(n+1,inf);
  dp[0] = 0;
  rep1(i,n+1) {
      rep(j,m) {
          if(i < data[j]) break;
          dp[i] = min(dp[i-data[j]]+1,dp[i]);
      }
  }
  cout << dp[n];
  hinata;
}


Measured memory_bytes: 3300
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    inf = float('inf')
    H = list(map(int, input().split()))
    dp = [inf] * n
    dp[0] = 0
    for i in range(1, n):
        if i == 1:
            dp[i] = dp[i-1] + abs(H[i] - H[i-1])
        else:
            dp[i] = min(dp[i-1] + abs(H[i] - H[i-1]),
                        dp[i-2] + abs(H[i] - H[i-2]))
    print(dp[n-1])

if __name__ == '__main__':
    main()

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

int main(){
    string s;
    cin >> s;
    string result = "No";
  bool x = true;
  bool y = true;
    for(int i=0; i<s.length(); i ++){
      if(i%2 == 0 && s[i] == 'L'){
		x = false;
      }
      
      if(i%2 == 1 && s[i] == 'R'){
		x = false;
      }
    }
  
  if(x && y) result = "Yes";
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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

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

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

////////////////////////////////////////////////////////////

int main() {
    int A, B, C;
    int X, Y, Z;
    cin >> X >> Y >> Z;
    A = X;
    B = Y;
    C = Z;
    swap(A, B);
    swap(A, C);
    printf("%d %d %d\n", A, B, C);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int p[M];
  string S[M];
  int mondai[N];
  int wrongSum = 0;
  int correctSum = 0;
  for (int i=0;i<N;i++){
    mondai[i]=0;
  }
  for(int i=0;i<M;i++){
    cin >> p[i] >> S[i];
    if (mondai[p[i]-1]!=-1){
      if(S[i][0]=='A'){
        wrongSum+=mondai[p[i]-1];
        mondai[p[i]-1]=-1;
        correctSum++;
      }else {
        mondai[p[i]-1]++;
      }
    }
  }
  cout << correctSum << " " << wrongSum;
}


Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=1000;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=1e9+7;
struct M{ int a[3][3]; };
inline M operator + (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			ans.a[i][j]=(a.a[i][j]+b.a[i][j])%mod;
	return ans;
}
inline M operator * (const M &a,const int &b) {
	M ans;
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			ans.a[i][j]=1LL*a.a[i][j]*b%mod;
	return ans;
}
inline M operator * (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			for (int k=0;k<3;k++)
				ans.a[i][j]=(ans.a[i][j]+1LL*a.a[i][k]*b.a[k][j])%mod;
	return ans;
}
const M zero=(M){{{0,1,3},{0,0,0},{0,0,0}}};
const M base=(M){{{4,1,0},{mod-2,0,1},{1,0,0}}};//f(n)=4f(n-1)-2f(n-2)+f(n-3)
inline M qpow(int y) {
	M ans={},x=base;
	ans.a[0][0]=ans.a[1][1]=ans.a[2][2]=1;
	while (y) {
		if (y&1) ans=ans*x;
		x=x*x;y>>=1;
	}
	return ans;
}
int x[N];
int main()
{
	int n=gi(),m=gi(),i,ans,x,last=0,t;M sum={};
	ans=(zero*qpow(n)).a[0][0];
	for (i=1;i<=m;i++,last=x) {
		x=gi();
		sum=sum*qpow(x-last);
		t=(zero*qpow(x)).a[0][0];
		t=(t-sum.a[0][0]+mod)%mod;
		ans=(ans-1LL*t*(zero*qpow(n-x)).a[0][0]%mod+mod)%mod;
		sum=sum+zero*t;
	}
	printf("%d\n",ans);
	return 0;
}


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

string a, b, c;

int main () {
  cin >> a >> b >> c;
  // ini mengubah karakter pertama dari a menjadi kapital
  a[0] = a[0] - 'a' + 'A';  
  b[0] = b[0] - 'a' + 'A'; 
  c[0] = c[0] - 'a' + 'A'; 
  a=a[0];
  b=b[0];
  c=c[0];
  cout << a << b << c;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define LL long long
#define maxn 200010
using namespace std;
int color[maxn],head[maxn],tot,n,Size[maxn],sum[maxn];
LL ans[maxn];
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
LL get_num(LL x){
	return x*(x+1)/2;
}
void dfs(int u,int fa){
	int v,b,c,t,dt;
	LL pre;
	Size[u]=1,c=color[u], pre=sum[c];//非u子树已算出的c颜色为根的节点数量
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		t=sum[c];
		dfs(v,u);
		dt=sum[c]-t;//遍历了v之后，c颜色对应的变化量
		Size[u]+=Size[v];
		ans[c]-=get_num(Size[v]-dt);
	}

	sum[c]=pre+Size[u];//总的c颜色为根的节点数量
	//cout << "u: " << u << "    pre: " << pre << "     c: " << c << "    sum: " << sum[c] << "     Size: " << Size[u] << "    ans: " << ans[c] << endl;
}
int main(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&color[i]);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
	for(i=1;i<=n;i++)ans[i]=get_num(n);
	dfs(1,0);
	for(i=1;i<=n;i++)ans[i]-=get_num(n-sum[i]);//n-sum[i]指离树根最近的i颜色之外的其他颜色(整棵树扣除所有以i颜色为根的子树)数量
	for(i=1;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
}

/*
7
1 2 4 1 2 3 1
1 2
1 3
2 4
2 5
3 6
3 7

10
1 2 4 1 2 3 1 5 6 7
1 2
1 3
2 4
2 5
3 6
3 7
4 8
7 9
7 10
*/


Measured memory_bytes: 27184
//ABC143
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i=0;i<n;i++){
		cin >> l.at(i);
	}
	sort(l.begin(),l.end());
	int ans = 0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			if(l.at(i)+l.at(j)<=l.at(j+1)){
				ans = ans;
			}else{
				auto num = lower_bound(l.begin(),l.end(),l.at(i)+l.at(j));
				int it = num-l.begin();
				it -= j+1;
				ans += it;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	int s = a + b + c;
	int mx = max(a,max(b, c));
	if (s % 2 == mx % 2) {
		cout << (mx * 3 - s) / 2 << endl;
	} else {
		cout << ((mx + 1) * 3 - s) / 2 << endl;
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
int lcm(int x,int y){
  return x/__gcd(x,y)*y;
}
int mpow(int n,int x){
  int res=1LL;
  for(int i=0;i<x;i++) res*=n;
  return res;
}
int mod_pow(int x,int n,int mod){
  int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}
int ker(int n){
  int res=1;
  map<int,int> m;
  for(int i=2;i*i<=n;i++){
    if(n%i) continue;
    while(n%i==0) n/=i,m[i]++;
  }
  if(n!=1) m[n]++;
  for(auto p:m){
    if(p.first==2){
      if(p.second==1) res=lcm(res,1);
      else if(p.second==2) res=lcm(res,2);
      else res=lcm(res,mpow(2,p.second-2));
    }else{
      res=lcm(res,mpow(p.first,p.second-1)*(p.first-1));
    }
  }
  return res;
}

signed main(){
  int n,b;
  cin>>n;
  b=n;
  map<int,int> m;
  for(int i=2;i*i<=n;i++){
    if(n%i) continue;
    while(n%i==0) n/=i,m[i]++;
  }
  if(n!=1) m[n]++;
  if(b==n){
    cout<<1<<endl;
    return 0;
  }
  if((int)m.size()>2){
    cout<<-1<<endl;
    return 0;
  }
  int x=-1,y;
  int ans=1LL;
  for(auto p:m){
    if(p.second>1){
      cout<<-1<<endl;
      return 0;
    }
    ans=lcm(ans,p.first-1);
    //cout<<ans<<endl;
    if(x<0) x=p.first;
    else y=p.first;
  }
  if(__gcd(x+y-1,(x-1)*(y-1))!=1LL){
    cout<<-1<<endl;
    return 0;
  }
  //cout<<x<<" "<<y<<endl;
  //cout<<x+y-1<<" "<<(x-1)*(y-1)<<endl;
  int k=ker(ans);
  //cout<<k<<" "<<ans<<endl;
  int tmp=k;
  for(int i=2;i*i<=k;i++){
    if(k%i) continue;
    //cout<<i<<" "<<mod_pow(x,mod_pow(b,i,ans),b)<<endl;
    //cout<<k/i<<" "<<mod_pow(x,mod_pow(b,k/i,ans),b)<<endl;
    if(mod_pow(b,i,ans)==1) tmp=min(tmp,i);
    if(mod_pow(b,k/i,ans)==1) tmp=min(tmp,k/i);
  }
  cout<<tmp<<endl;
  return 0;
}

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

#define int long long

struct Combination
{
  int mod;
  vector<int> mfact;
  vector<int> rfact;

  /*
    constructor : O(sz+log(mod))    
   */
  Combination(int sz, int mod) : mfact(sz+1), rfact(sz+1), mod(mod) {
    mfact[0] = 1;
    for ( int i = 1; i < (int)mfact.size(); i++ ) {
      mfact[i] = mfact[i-1]*i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      rfact[i] = rfact[i+1]*(i+1) % mod;
    }
  }

  int fact(int k) const {
    return (mfact[k]);
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int inv(int x) const {
    return (pow(x, mod - 2));
  }

  /*
    permutation
   */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return (mfact[n]*rfact[n-r] % mod);
  }

  /*
    combination
   */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return (mfact[n]*rfact[r]%mod * rfact[n-r]%mod);    
  }  

  /*
    combination with repetition
   */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return (0);
    return (r == 0 ? 1 : C(n+r-1, r));
  }

  /*
    stirling number
   */
  int S(int n, int r) const {
    int ret;
    for ( int i = 1; i <= r; i++ ) {
      
    }
  }

  /*
    bell number
   */
  int B(int n, int r) const {

  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, k;
  cin >> n >> k;

  Combination c(1000, 1e9+7);
  cout << c.pow(k, n) << endl;  
  
  return 0;
}



Measured memory_bytes: 3236
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long n = nk[0];
			long k = nk[1];
			long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			Array.Sort(a);

			long ok = (long)(-1e18) - 1;
			long ng = (long)(1e18) + 1;
			while (ng - ok > 1) {
				long mid = (ng + ok) / 2;
				long cnt = 0;
				for (int i = 0; i < n; i++) {
					if (a[i] < 0) {
						cnt += n - LowerBoundIntR(i, a.Length, midd => a[i] * a[midd] < mid);
					} else {
						cnt += LowerBoundIntL(i, a.Length, midd => a[i] * a[midd] < mid) - i;
					}
				}

				if (cnt < k) {
					ok = mid;
				} else {
					ng = mid;
				}
			}

			Console.WriteLine(ok);
		}

		public static int LowerBoundIntR(int ng, int ok, Func<int, bool> check)
		{
			while (ok - ng > 1) {
				int mid = (ok + ng) / 2;
				if (check(mid)) {
					ok = mid;
				} else {
					ng = mid;
				}
			}

			return ok;
		}

		public static int LowerBoundIntL(int ok, int ng, Func<int, bool> check)
		{
			while (ng - ok > 1) {
				int mid = (ok + ng) / 2;
				if (check(mid)) {
					ok = mid;
				} else {
					ng = mid;
				}
			}

			return ok;
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

int main(void)
{
    long long N;
    cin >> N;
    vector<long long> vec(N);
    
    for (auto i = 0; i < N; i++) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    
    
    cout << vec[N-1] - vec[0] << endl;
}


Measured memory_bytes: 3544
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e7+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    int a[n];
    lp(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    int x=0,res=0;
    for(int i=n-1;i>=0;i--){
        if(x&1)
            res-=a[i];
        else
            res+=a[i];
        x++;
    }
    cout<<res;


}

Measured memory_bytes: 3628
N=int(input())
A=list(map(int,input().split()))


def ch(x,y):
    lx=len(bin(x))-2
    ly=len(bin(y))-2
    L=min(lx,ly)
    for i in range(L):
        if (x&1) and (y&1):
            return False
        x=x>>1
        y=y>>1
    return True

ans=0
temp=0
l=0
for i in range(N):
    if ch(temp,A[i]):
        temp+=A[i]
        L=i+1-l
        ans+=L
    else:
        while not (ch(temp,A[i])):
            temp-=A[l]
            l+=1
        temp+=A[i]
        L=i+1-l
        ans+=L


print(ans)
        








Measured memory_bytes: 87244
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int l[10],v1,v2;
  int result,ans;
  double total, time, distance;

  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF){

    total=0;
    for(int i=0; i<10; i++)
      total += l[i];
    time = (double)total/(v1+v2);
    distance = v1 * time;
    result = 0;
    for(ans=0; result < distance; ans++)
      result += l[ans];
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int mod = (int) (Math.pow(10, 9)+7);
		long ans = 1;
		for(int i = 1; i <= n ; i++) {
			ans *= i;
			ans%=mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<vector<int>>t(N+1,vector<int>(3));
  t.at(0).at(0)=0;
  t.at(0).at(1)=0;
  t.at(0).at(2)=0;
  
  for(int i=1;i<=N;i++){
    cin>>t.at(i).at(0)>>t.at(i).at(1)>>t.at(i).at(2);
  }
  for(int i=0;i<N;i++){
    int s= t.at(i+1).at(0)- t.at(i).at(0);
    int x= t.at(i+1).at(1)- t.at(i).at(1);
    	if(x<0){x=-x;}
    int y= t.at(i+1).at(2)- t.at(i).at(2);
    	if(y<0){y=-y;}
    int l= x+y;
    if(s<l){
      cout <<"No"<<endl;
      return 0;
    }
    if(s%2!=l%2){
      cout <<"No"<<endl;
      return 0;
    }
  }
  
  cout <<"Yes"<<endl;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  if(A>=K)return cout<<K<<endl,0;
  else if(A+B>=K)return cout<<A<<endl,0;
  else return cout<<2*A+B-K<<endl,0;
}

Measured memory_bytes: 3632
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const n = parseInt(input[0], 10);
    const a = input[1].split(' ').map(function(value) { return parseInt(value, 10); });
    const aMinusI = a
    .map(function(value, index) {
        return value - (index + 1);
    })
    .sort(function (a, b) {
        if (a < b) {
            return -1;
        }
        else if (a > b) {
            return 1;
        }
        else {
            return 0;
        }
    });

    const b = aMinusI[Math.floor(n / 2)];

    const ans = aMinusI
    .map(function(value) {
        return Math.abs(value - b);
    })
    .reduce(function(prev, current) {
        return Math.abs(prev + current);
    });

    console.log(ans);

    return 0;
}


Measured memory_bytes: 36888
#include <iostream>
#include <cstdlib>

int main(void) {
    int x;
    int y;
    int s;
    int before;
    int temp_after;
    int after;

    std::cin >> x >> y >> s;

    while (x != 0) {
        after = 0;
        for (int i = 0; i < s; i++) {
            for (int j = i; j < s; j++) {
                before = (int)((double)(i + 1) * (double)(100 + x)) / 100 + (int)((double)(j + 1) * (double)(100 + x)) / 100;
                //std::cout << "I = " << i + 1 << ", J = " << j + 1 << std::endl;
                //std::cout << before << std::endl;
                if (before == s) {
                    temp_after = (int)((double)(i + 1) * (double)(100 + y)) / 100 + (int)((double)(j + 1) * (double)(100 + y)) / 100;
                    /*
                    std::cout << "I = " << i + 1 << ", J = " << j + 1 << std::endl;
                    std::cout << before << std::endl;
                    std::cout << (int)((double)(i + 1) * (double)(100 + y)) / 100 << std::endl;
                    std::cout << (int)((double)(j + 1) * (double)(100 + y)) / 100 << std::endl;
                    std::cout << temp_after << std::endl;
                    */
                    if (temp_after > after) {
                        after = temp_after; 
                    }
                }
            }
        }
        std::cout << after << std::endl;
        std::cin >> x >> y >> s;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3068
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    input!{a:usize,b:usize,c:usize}
    use std::cmp;
    println!("{}",cmp::max(10*a+b+c, cmp::max(a+10*b+c, a+b+10*c)));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long num=0;
    for(int i=1;i<n;i++){
        if(a[i]>=a[i-1]){
            continue;
        }
        while(a[i]<a[i-1]){
            a[i]++;
            num++;
        }
    }
    cout<<num<<endl;
}
  
   

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

bool isEvenString(string s, int len)
{
    for (int ptr = 0; ptr < len/2; ++ptr){
        if (s[ptr] != s[ptr + len/2]){
            return false;
        }
    }
    return true;
}

signed main()
{
    string s; cin >> s;

    int len = s.size();
    for (int i=len-2; i >=2; i-=2){
        if (isEvenString(s,i)){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define COUT(x) cout << (x) << endl
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;


int main() {
    int n;
    cin >> n;
    ll ans = 0;
    rrep(i, n) {
        if((i % 3 == 0) || (i % 5 == 0)) continue;
        ans += i;
    }
    COUT(ans);
    
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void)
{
  int N;
  scanf("%d",&N);
  int P[N];
  
  for (int i = 0;i < N; i++)
  {
    scanf("%d",&P[i]);
  }
  
  int min = P[0];	//最小値(タイ含む)更新したときのみカウント！！
  int result = 1;
  for (int i = 1; i < N; i++)
  {
    if (P[i]<=min)
    {
      min = P[i];
      result++;
    }
  }
  printf("%d",result);
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    string S;
    cin >> N >> S;
    int sum[N+1];
    sum[0]=0;
    rep(i,N){
        int x=0;
        if(S.at(i)=='W') x=1;
        sum[i+1]=sum[i]+x;
    }
    int ans=N-1-(sum[N]-sum[1]);
    for(int i=0;i<N;i++){
        ans=min(ans,sum[i]+N-i-1-(sum[N]-sum[i+1]));
    }
    cout << ans << endl;



}



Measured memory_bytes: 1812
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int solve(int A, int X, int Y) {
	int g = gcd(X, Y);

	int l = (X / g) * Y;
	
	
	return A - ((A / X) + (A / Y) - (A / l));


}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int res = solve(B, C, D) - solve(A - 1, C, D);
	cout << res << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;

char s[100010];

int main(){
	scanf("%s",s + 1);
	int len = strlen(s + 1);
	bool f = false;
	for(int i = 1; i < len; ++i){
		if(s[i] == s[i + 1]){
			printf("%d %d\n",i,i + 1);
			f = true;
			break;
		}
		if(i < len - 1 && s[i] == s[i + 2]){
			printf("%d %d\n",i,i + 2);
			f = true;
			break;
		}
	}
	if(f == false){
		printf("-1 -1\n");
	}
	return 0;
}

Measured memory_bytes: 384
import math
a,b,c = map(float, input().split())
print(0.5*a*b*math.sin(c/180*math.pi))
print(a+b+math.sqrt(a**2 + b**2 - 2*a*b*math.cos(c/180*math.pi)))
print(b*math.sin(c/180*math.pi))


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

int main()
{
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    long long ans=0,d;
    if(k%2==0){
        d=n/k;
        if(n%k>=k/2)
            d++;
        ans+=(d*d*d);
    }
    d=n/k;
    ans+=d*d*d;
    cout<<ans<<endl;
    return 0;
}


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

#define INF ((1LL <<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

#define LIMIT_SEC 1.98

class Timer {
    chrono::high_resolution_clock::time_point start;
public:
    double limit;
    Timer() {
        start = chrono::high_resolution_clock::now();
        limit = LIMIT_SEC;
    }
    Timer(double limit) :limit(limit) {
        start = chrono::high_resolution_clock::now();
    }
    double get_time() {
        return chrono::duration<double>(chrono::high_resolution_clock::now() - start).count();
    }
    bool time_over() {
        if (get_time() > limit) {
            return true;
        }
        return false;
    }
    void set_start() {
        start = chrono::high_resolution_clock::now();
    }
    double get_limit() {
        return limit;
    }
};

Timer timer;

// 乱数器
class XorShift {
public:
    unsigned long x, y, z, w;
    XorShift() {
        x = 123456789; y = 362436069; z = 521288629; w = 88675123;
    }
    XorShift(unsigned long seed) {
        XorShift();
        w = seed;
        for (int i = 0; i < 100; ++i) (*this)();
    }
    unsigned long operator()() {
        unsigned long t = x ^ (x << 11);
        x = y; y = z; z = w;
        return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    }
};

XorShift rnd;

ll c[27];
ll s[366][27];

const int C = 26;

ll bestScore = 0;
ll lc[C];

ll csum[C][367];

vector<int> ans(365, 0);

ll getScore() {
    ll ret = 0;
    for (int d = 0; d < 365; ++d) {
        ret += s[d][ans[d]];
        lc[ans[d]] = d+1;
        rep(i, C) {
            ret -= c[i] * ((d+1) - lc[i]);
        }
    }
    return ret;
}


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

    int D;
    cin >> D;
    rep(i, C) cin >> c[i];
    rep(i, D) rep(j, C) cin >> s[i][j];

    // 0日目は0
    // 増えて行くのは1日目から(0-index)
    for (int i = 0; i < C; ++i) {
        for (int d = 0; d < 366; ++d) {
            if (d == 0) continue;
            else {
                csum[i][d] += (csum[i][d-1] + c[i]);
            }
        }
    }

    // makeGreedy
    rep(d, D) {
        int ma = 0, idx = 0;
        rep(i, C) {
            if (ma < s[d][i]) {
                ma = s[d][i];
                idx = i;
            }
        }
        ans[d] = idx;
    }
    bestScore = getScore();
    vector<int> bestAns = ans;

    Timer timer;
    double startTime = timer.get_time();
    double nowTime = startTime;
    while (true) {
        nowTime = timer.get_time();
        if (nowTime - startTime > LIMIT_SEC) break;

        int d = rnd()%D;

        int change = rnd()%C;
        int prev = ans[d];
        ans[d] = change;

        ll tmp = getScore();
        if (tmp > bestScore) {
            cerr << "Update: " << bestScore << endl;
            bestScore = tmp;
            bestAns = ans;
        }
        else {
            ans[d] = prev;
        }
    }


    rep(i, D) cout << bestAns[i] + 1 << endl;
    cerr << bestScore << endl;
}


Measured memory_bytes: 3816
#include<iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main(){
  int nmin,nmax;
  cin >> nmin >> nmax;
  string num;
  int count=0;
  for(int i=nmin;i<=nmax;i++){
	num = to_string(i);
    if(num.at(0) == num.at(4) && num.at(1) == num.at(3)){
      count++;
    }
  }
  
  cout << count << endl;
}
  


Measured memory_bytes: 3660
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char a[1200], k;
    int i,j, n=0, c[26];
    while(scanf("%c", &k) != EOF){
        a[n] = k;
        n++;
    }
    for(i=0; i<26; i++){
        c[i]=0;
    }
    for(i=0; i<n; i++){
        if(a[i]>=65 && a[i]<=90){
            a[i]+=32;
        }
        if('a'<=a[i] && a[i]<='z'){
            j = a[i] - 'a';
            c[j]++;
        }
    }
    for(i=0; i<26; i++){
        printf("%c : %d\n", i+97, c[i]);
    }
    return 0;
}


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

int main()
{
int n;
cin>>n;
vector<double> v(n);
for(int i=0;i<n;i++)
cin>>v[i];
double dp[n+1][n+1];
dp[0][0]=1;
for(int i=1;i<=n;i++)
dp[0][i]=dp[0][i-1]*(1-v[i-1]);
for(int i=1;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
if(j<i)
dp[i][j]=0;
else
dp[i][j]=dp[i-1][j-1]*v[j-1]+dp[i][j-1]*(1-v[j-1]);
}
}
double res=0;
for(int i=n/2+1;i<=n;i++)
{
res+=dp[i][n];
}
printf("%.10lf\n",res);
//cout<<res<<endl;
return 0;
}

Measured memory_bytes: 70528
k, n, *a = map(int, open(0).read().split())
a.append(k + a[0]) # 円環は2周する
ans = 0
for i in range(n):
    ans = max(ans, a[i + 1] - a[i]) # 最も間隔のある家を両端にすると最小
print(k - ans)

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> c;
    /**/
    int rcount = 0,wcount = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'R'){
            c.push_back(1);
            rcount++;
        }
        else{
            c.push_back(0);
            wcount++;
        }
    }

    int count = 0;
    for(int i = 0;i < rcount;i++){
        if(c[i] == 0) count++;
    }

    cout << count << endl;

    return 0;
}

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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;
    }

    public static string Solve()
    {
        int[] input = ReadInts();
        int A = input[0];
        int B = input[1];
        if(A==B)
        {
            return (A + B).ToString();
        }
        else
        {
            return (Math.Max(A, B) * 2 - 1).ToString();
        }
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


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

#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)

#define ii pair<int, int>
#define mp make_pair
#define FF first
#define SS second

#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

#define eb emplace_back
#define ef emplace_front
#define lb lower_bound
#define ub upper_bound

#define oo 1000000007
#define OO 1000000000000000007LL

using namespace std;

#define Pro "tmp"
#define maxN 300007

int main() {
    int T;
    scanf("%d", &T);

    fto (i_test, 1, T) {
        ll a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

        if (d < b || a < b) {
            puts("No");
            continue;
        }

        if (c >= b) {
            puts("Yes");
            continue;
        }

        bool valid = 1;
        ll tmp = a;

        fto (k, 1, 10000) {
            if (a < b) {
                puts("No");
                valid = 0;
                break;
            }
            a %= b;
            if (a <= c) {
                if (d%b == 0) break;
                a += d;
            }
        }

        a = tmp;
        if (!valid) continue;

        fto (k, 1, 10000) {
            a %= b;
            if (a <= c) {
                if (d%b == 0) break;
                a += ((c-a)/(d%b)+1)*(d%b);
            }
            else {
                puts("No");
                valid = 0;
                break;
            }
        }

        if (valid) puts("Yes");
    }

    return 0;
}


Measured memory_bytes: 256
use List::Util qw/ max /;

my ($n, $m) = split ' ', <>;
my @h = split ' ', <>;
my %routes = map { $_ => [] } (1..$n);
for my $i (1..$m) {
    my ($tmp_a, $tmp_b) = split ' ', <>;
    push @{$routes{$tmp_a}}, $tmp_b;
    push @{$routes{$tmp_b}}, $tmp_a;
}
my $ans = 0;
for my $i (keys %routes) {
    unless(@{$routes{$i}}) {
        ++$ans;
        next;
    }
    if($h[$i-1] > max(map { $h[$_-1] } @{$routes{$i}})) {
        ++$ans;
    }
}

print $ans;

Measured memory_bytes: 71220
n = int(input())
rs = [list(input().split()) for _ in range(n)]


new_rs = sorted(rs, key=lambda x: - int(x[1]))


def mp_count(s):
    mps = {}
    for mp, _ in s:  # 2個の変数を用意しないと、1個の変数にリストがいい感じにおさまってしまう
        if mp not in mps:
            mps[mp] = 0
    return sorted(mps)


for m in mp_count(rs):
    for r in new_rs:
        if m == r[0]:
            print(rs.index(r) + 1)


Measured memory_bytes: 3060
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	s1 := string(s[0]) + string(s[1])
	s2 := string(s[2]) + string(s[3])
	s3, _ := strconv.Atoi(s1)
	s4, _ := strconv.Atoi(s2)

	result := "AMBIGUOUS"
	if s4 < 13 && s4 > 0 {
		if s3 < 13 && s3 > 0 {
			result = "AMBIGUOUS"
		} else {
			result = "YYMM"
		}
	} else {
		if s3 < 13 && s3 > 0 {
			result = "MMYY"
		} else {
			result = "NA"
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;


int main(void) {
	string s; cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int w, h;

int map[200][200];

void search(int x, int y, int col){
	if(x < 0 || y < 0 || x > w || y > h){
		return;
	}
	if(map[x][y] != col || map[x][y] == 0){
		return;
	}
	map[x][y] = 0;
	search(x - 1, y, col);
	search(x + 1, y, col);
	search(x, y - 1, col);
	search(x, y + 1, col);
}

int main(){
	
	
	while(true){
		
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		
		int xs, ys, xg, yg;
		
		cin >> xs >> ys >> xg >> yg;
		
		int n;
		
		cin >> n;
		
		for(int i = 0; i <= w; i++){
			for(int j = 0; j <= h; j++){
				map[i][j] = 0;
			}
		}
		
		for(int loop = 0; loop < n; loop++){
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			if(d == 0){
				for(int dx = 0; dx < 4; dx++){
					for(int dy = 0; dy < 2; dy++){
						map[x + dx][y + dy] = c;
					}
				}
			}else{
				for(int dx = 0; dx < 2; dx++){
					for(int dy = 0; dy < 4; dy++){
						map[x + dx][y + dy] = c;
					}
				}
			}
		}
		
		if(map[xs][ys] == 0 || map[xg][yg] == 0){
			cout << "NG" << endl;
		}else{
			search(xs, ys, map[xs][ys]);
			if(map[xg][yg] == 0){
				cout << "OK" << endl;
			}else{
				cout << "NG" << endl;
			}
		}
		/*
		for(int y = 1; y <= h; y++){
			for(int x = 1; x <= w; x++){
				cout << map[x][y];
			}
			cout << endl;
		}
		*/
	}
	
	return 0;
}

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

int main()
{
	int a,b;
	char c;
	cin >> a >> c >> b;
	if(c == '+'){a = a + b; cout << a << endl;}
	else if(c == '-'){a = a - b; cout << a << endl;}
	else if(c == '*'){a = a * b; cout << a << endl;}
	else if(c == '/'){a = a / b; cout << a << endl;}
return 0;
}

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

int main() {
	int a;
    cin>>a;
    int count=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==a){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
const int MOD = 1e9+7;
const int MAXN = 2e5+5;

int32_t main()
{
    
    IOS
    int n;
    cin>>n;
    cout<<3*(n*n)<<'\n';
    return 0;
}
        

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

int main(){
	int num[100] = {0}, max = 0, input;
	while(cin>>input){
		num[input-1]++;
	}
	for(int i=0;i<100;i++){
		if(max<num[i])
			max = num[i];
	}
	for(int i=0;i<100;i++){
		if(max == num[i])
			cout << i+1 << endl;
	}
	return 0;
}

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

int main() {
  long long N,A,B,ans;
  cin >>N>>A>>B;
  if(abs(A-B)%2==0){
ans=abs(A-B)/2;
  }
  else{
    ans=min(N-max(A,B)+1+abs(min(A,B)-max(A,B)+1)/2,min(A,B)+abs(max(A,B)-min(A,B)-1)/2);
  }
  cout << ans<< endl;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int> >;
using vii = vector<pair<int, int> >;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int a, b, c; cin >> a >> b >> c;

	if (a != b && b == c) cout << a << endl;
	else if (b != c && c == a) cout << b << endl;
	else cout << c << endl;

}

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

using namespace std;

void solve(int N, vector<int> A, vector<int> B) {
  long long cnt = 0;
  for (int i = 0; i < N; i++) {
    int x = min(A[i], B[i]);
    cnt += x;
    int y = min(A[i + 1], B[i] - x);
    cnt += y;
    A[i + 1] -= y;
  }
  printf("%lld\n", cnt);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  vector<int> B(N);
  for (int i = 0; i < N + 1; i++) {
    int x;
    cin >> x;
    A[i] = x;
  }
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    B[i] = x;
  }
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <string>
#include <time.h>


using namespace std;

int main(void) {



	int a = 0, b = 0,c=0;
	int k=0;
	int sum = 0;
	cin >> a >> b >> c;
	cin >> k;
	if (a >= b && a >= c) {

		for (int i = 0; i < k; i++)
			a = a * 2;


		sum = a + b + c;

	}
	else if (b >= a && b >= c) {


		for (int i = 0; i < k; i++)
			b = b * 2;


		sum = a + b + c;


	}else{

		for (int i = 0; i < k; i++)
			c = c * 2;


		sum = a + b + c;
	}


	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main (String [] args){
        Scanner sc =new Scanner(System.in);
        int i=0;
        int n =sc.nextInt();
        int[] t;
        t = new int[n];
      
        while(i<n){
            int H =sc.nextInt();
            t[i]=H;
            i++;
        }
        System.out.print(t[n-1]);
        
        for(int b=n-2;b>=0;b--){
            
            System.out.print(" "+t[b]);
        }
        System.out.println();
       
        sc.close();
   }
 
}


Measured memory_bytes: 26204
def solve(s):
    if all(a == b for a, b in zip(s, s[1:])):
        return 1
    if len(s) == 2:
        return 2
    elif len(s) == 3:
        if s[0] == s[1] or s[1] == s[2]:
            return 6
        elif s[0] == s[2]:
            return 7
        else:
            return 3
    # dp[has succession=0][mod 3][last char], dp[has succession=1][mod 3]
    dp = [[[0] * 3 for _ in range(3)], [0] * 3]
    dp[0][0][0] = 1
    dp[0][1][1] = 1
    dp[0][2][2] = 1
    MOD = 998244353
    for _ in range(len(s) - 1):
        ndp = [[[0] * 3 for _ in range(3)], [0] * 3]
        dp0, dp1 = dp
        ndp0, ndp1 = ndp
        sdp1 = sum(dp1)
        ndp0[0][0] = (dp0[0][1] + dp0[0][2]) % MOD
        ndp0[1][0] = (dp0[1][1] + dp0[1][2]) % MOD
        ndp0[2][0] = (dp0[2][1] + dp0[2][2]) % MOD
        ndp0[0][1] = (dp0[2][0] + dp0[2][2]) % MOD
        ndp0[1][1] = (dp0[0][0] + dp0[0][2]) % MOD
        ndp0[2][1] = (dp0[1][0] + dp0[1][2]) % MOD
        ndp0[0][2] = (dp0[1][0] + dp0[1][1]) % MOD
        ndp0[1][2] = (dp0[2][0] + dp0[2][1]) % MOD
        ndp0[2][2] = (dp0[0][0] + dp0[0][1]) % MOD
        ndp1[0] = (dp0[0][0] + dp0[1][2] + dp0[2][1] + sdp1) % MOD
        ndp1[1] = (dp0[1][0] + dp0[2][2] + dp0[0][1] + sdp1) % MOD
        ndp1[2] = (dp0[2][0] + dp0[0][2] + dp0[1][1] + sdp1) % MOD
        dp = ndp
    return (dp[1][sum(map(ord, s)) % 3] + all(a != b for a, b in zip(s, s[1:]))) % MOD


s = input()
print(solve(s))


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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256