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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

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

	int n, t, i, j, k, x, y, z;

	x = y = t = 0;
	cin >> n;
	while (n--) {
		int a, b, c;
		cin >> a >> b >> c;
		int tmp = abs(x - b) + abs(y - c);
		int nt = a;
		a -= tmp;
		a -= t;
		if (a < 0 || (a&1)) {
			cout << "No" << endl;
			return 0;
		}
		t = nt;
		x = b;
		y = c;
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            int x = Integer.parseInt(str[0]);
            int y = Integer.parseInt(str[1]);
            int z = Integer.parseInt(str[2]);
            boolean flag = true;
            int num = 0;
            int ans = 0;
            while (num < x) {
                if (flag) {
                    num += z;
                } else {
                    if (num + y <= x) {
                        num += y;
                        ans++;
                    } else {
                        break;
                    }
                }
                flag = !flag;
            }
            if (y * ans + z * (ans + 1) > x) {
                ans--;
            }
            System.out.println(ans);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) { for (auto& e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int M, D; cin >> M >> D;
	int cnt = 0;
	rep(m, 1, M + 1) {
		rep(d, 1, D + 1) {
			if (d >= 20 && (d % 10) >= 2 && (d/10)*(d%10) == m) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
//csjosh

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required
// using namespace __gnu_pbds; //required 
using namespace std;

#define ll long long 
#define loop(x) for(int i=0;i<x;i++)

#define llu unsigned long long 
#define pb push_back
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define dd fflush(stdout)
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mt make_tuple //use tie
#define eb emplace_back
typedef tuple<int,int,int> State;//use in dijkstra
ll mod=1e9+7;
// ll power(ll x,ll y,ll mod){
//  ll ans=1;
//  while(y>0){
//   if(y&1){
//     ans=ans*x;
//   }
//   x=x*x;
//   y=y/2;
//  }
//  return ans;
// }

// typedef tree<
// pair<int, int>,
// null_type,
// less<pair<int, int>>,
// rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
 string s;
 int n;
    int d;
   ll dp[10000+5][105][3];
ll solve(int idx,int tight,int sum){
   
   ll ans=0;
   if(idx==n){
    if(sum%d==0)
    {
      return 1;
    }
    else
      return 0;
   }
   int new_tight;
   if(dp[idx][sum][tight]!=-1)
   { 
    return dp[idx][sum][tight];
   }
  int k=((tight==1)?(s[idx]-'0'):9);
   for(int i=0;i<=k;i++){
    // cout<<i<<" "<<s[idx]<<" "<<tight<<" "<<k<<endl;
    if(tight==1 && i==k){
      new_tight=1;
    }
    else
      new_tight=0;
    ans=(ans+solve(idx+1,new_tight,(sum+i)%d))%mod;
   }
   return dp[idx][sum][tight]=(ans%mod);
}    
int main(){
    IOS;  
   memset(dp,-1,sizeof dp);
    cin>>s>>d;
// index,tight,sum
   n=s.length();
    cout<<((solve(0,1,0)-1+mod)%mod)<<endl;
 }



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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	map<int, int> b;
	for (int i = 0; i < N; i++)b[a[i]]++;
	if (b.size() == 3) {
		int A[3], B[3];
		for (int i = 0; i < 3; i++) {
			auto itr = b.begin();
			for (int j = 0; j < i; j++)itr++;
			auto tmp = *itr;
			A[i] = tmp.first;
			B[i] = tmp.second;
		}
		if ((A[0] ^ A[2]) == A[1] || (A[0] ^ A[1]) == A[2]) {
			if (B[0] == B[1] && B[1] == B[2]) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	else if (b.size() == 1) {
		if (a[0] == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	else if (b.size() == 2) {
		auto itr = b.begin();
		auto A = *itr;
		itr++;
		auto B = *itr;
		if (A.first == 0) {
			if (A.second == N / 3 && B.second == N / 3 * 2) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else {
			if (B.first == 0) {
				if (B.second == N / 3 && A.second == N / 3 * 2) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;

}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);

		double a = scan.nextDouble();
		double b = scan.nextDouble();
		double kado = scan.nextDouble();

		//?§???????????????¢????????????
		double radianC = Math.toRadians(kado);

		double area = 0;
		//??¢???????±?????????¬???????????¨
		area = a * b * Math.sin(radianC) / 2.0;

		double c = 0;
		//???????????????????±?????????¬???????????¨
		c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2)- (2 * a * b *Math.cos(radianC)));
		//??????
		double abc = a + b + c;
		
		//??????????±?????????¬????????¨
		double h = b * Math.sin(radianC);


		System.out.println(area);
		System.out.println(abc);
		System.out.println(h);
	}

}

Measured memory_bytes: 18196
from collections import deque

H, W = map(int, input().split())
ch, cw = map(lambda x: int(x)-1, input().split())
dh, dw = map(lambda x: int(x)-1, input().split())
S = [list(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]

q = deque()
q.append((0, ch, cw))
while q:
    c, h, w = q.popleft()
    if dist[h][w] >= 0:
        continue
    dist[h][w] = c
    for hh in range(-2, 3):
        for ww in range(-2, 3):
            if 0 <= h+hh < H and 0 <= w+ww < W and S[h+hh][w+ww] == "." and dist[h+hh][w+ww] < 0:
                if (hh, ww) in ((0,1), (1,0), (-1,0), (0,-1)):
                    q.appendleft((c, h+hh, w+ww)) # 徒歩は前に追加
                else:
                    q.append((c+1, h+hh, w+ww)) # ワープは後ろに追加

print(dist[dh][dw])

Measured memory_bytes: 218228
def delta(t1,t2):
	dt = [int(t2[i]) - int(t1[i]) for i in [0,1,3,4]]
	dt = 60*(10*dt[0] + dt[1]) + 10*dt[2] + dt[3]
	return dt
	
n,t = map(int,raw_input().split())
s = [raw_input().split() for i in range(n)]
a = []
for i in range(1,n):
	dt = delta(s[i-1][2],s[i][0])
	if dt >= t:
		a.append([s[i][1],str(dt)])
print len(a)
for i in a:
	print " ".join(i)

Measured memory_bytes: 4240
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n;
  cin >> n;
  vi a(n+1);
  rep(i,n+1) cin >> a[i];
  vi b(n) ;
  rep(i,n) cin >> b[i];
  vi c = a;
  ll sum = 0;

  for(int i = n-1;i>=0;i--){
    int p = a[i+1];
    int q = b[i];
    a[i+1] = max(p - q,0);
    b[i] = max(q - p,0);
    a[i] = max(a[i] - b[i],0);
    
  }
  rep(i,n+1){
    //cout << a[i] << " " << i  << endl;
    sum += c[i] - a[i];
  }
  cout << sum << endl;
}


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

using namespace std;

int H,W;
bool red[501][501];
bool blue[501][501];

int main() {
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(j == 0 || (i % 2 == 0 && j < W - 1)) red[i][j] = true;
      else blue[i][j] = true;
    }
  }

  for(int i = 0; i < H; i++) {
    string S;
    cin >> S;
    for(int j = 0; j < S.length(); j++) {
      if(S[j] == '#') red[i][j] = blue[i][j] = true;
    }
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(red[i][j])cout <<'#';
      else cout <<'.';
    }
    cout << endl;
  }
  cout << endl;

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(blue[i][j])cout <<'#';
      else cout <<'.';
    }
    cout << endl;
  }
}
      
  
  


Measured memory_bytes: 1280
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
dx = [1,1,1,0,0,-1,-1,-1]
dy = [1,0,-1,1,-1,1,0,-1]
for j in range(H):
    for i in range(W):
        cnt = 0
        for k in range(8):
            if 0<=i+dx[k]<W and 0<=j+dy[k]<H:
                if S[j+dy[k]][i+dx[k]]=="#":
                    cnt += 1
        if S[j][i] == "#":
            continue
        else:
            S[j][i] = cnt


for i in range(H):
    for j in range(W):
        S[i][j] = str(S[i][j])

for i in range(H):
    print("".join(S[i]))

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

int main(){
  long int X; cin >> X;
  long int temp = 0;
  int i=1;
  while(temp<X){
    temp += i;
    i++;
  }
  cout << i-1 << "\n";
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    map<int, lint> mp;
    rep(i, n){
        scanf("%d", &a[i]);
        ++mp[a[i]-i];
    }
    lint ans = 0;
    rep(i, n-1){
        --mp[a[i]-i];
        ans += mp[-a[i]-i];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 27152
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 20005;
const int K = 50;
vector < int > g[N];
double b[N], a[N], dp[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
    }
    for (int v = n - 1; v >= 1; v--){
        int deg = g[v].size();
        dp[v] = 1;
        for (auto u: g[v]){
            dp[v] = dp[v] + (double)(dp[u]) / deg;
        }
    }
    for (int v = n - 1; v >= 1; v--){
        for (int u = 1; u <= n; u++) b[u] = 0;
        b[v] = 1;
        for (int j = v - 1; j >= 1; j--){
            int deg = g[j].size();
            for (auto u: g[j]){
                b[j] = b[j] + (double) b[u] / deg;
            }
        }
        a[v] = b[1];
    }
    double oldans = dp[1];
    double ans = oldans;
   // cout << ans << endl;
    for (int i = n - 1; i >= 1; i--){
        if (g[i].size() == 1) continue;
        int deg = g[i].size();
        for (auto u: g[i]){
            double delta = a[i] * (((dp[i] - 1) * deg - dp[u]) / (deg - 1) + 1 - dp[i]);
            //cout << i << " " << u << " " << delta << " " << ans + delta << endl;
            ans = min(ans, oldans + delta);
        }
    }
    cout << fixed << setprecision(10) << ans;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 1e7 + 10, mod = 998244353;
int fact[N], invfact[N];
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (((ll) x) * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}
int p2[N];
void pre(){
	fact[0] = invfact[0] = p2[0] = 1;
	for(int i = 1;i < N; i++) fact[i] = mul(i, fact[i - 1]), p2[i] = add(p2[i - 1], p2[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for(int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k){
	if(n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int f(int n){
	int ret = powr(3, n);
	for(int i = n / 2 + 1; i <= n; i++){
		// trace(p2[n - i + 1], C(n, i), i);
		ret = sub(ret, mul(p2[n - i + 1], C(n, i)));
	}
	return ret;
}

int main(){
	pre();
	int n; sd(n); printf("%d\n", f(n));
}

Measured memory_bytes: 117376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()
 

int main(){
  ll x;
  cin >> x;
  cout << 1-x << endl;
}

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

int main (){
    long long L, R;
    cin>>L>>R;
    if(L%2019==0||R%2019==0||L/2019<R/2019){
        cout<<0<<endl;
    }
    else{
        L%=2019;
        R%=2019;
        int Min=2018;
        for(int i=L; i<R+1; i++){
            for(int j=i+1; j<R+1; j++){
                int X=i*j%2019;
                Min=min(Min, X);
            }
        }
        cout<<Min<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
int n;
char s[20];
vi ans;
string g(int x){
	string res;
	while(x)res+=x%10+'0', x/=10;
	reverse(res.begin(), res.end());
	return res;
}
bool qry(ll x){
	printf("? %lld\n", x);
	fflush(stdout);
	scanf("%s", s);
	if(s[0]=='Y')return 1;
	return 0;
}
ll g(){
	ll res=0;
	rep(i, 0, sz(ans))res=res*10+ans[i];
	return res;
}
int main() {
	//scanf("%d", &n);
	
	/*int a=2, b=20;
	rep(i, 1, 300){
		int a=i, b=29;
		cout<<a<<' '<<b<<' '<<((a<=b&&g(a)<=g(b))||(a>b&&g(a)>g(b)))<<endl;
		//a*=10;
	}
	*/
	/*int x=1, y=10;
	cout<<x<<' '<<y<<' '<<((x<=y&&g(x)<=g(y))||(x>y&&g(x)>g(y)))<<endl;*/
	int len=0;
	ll a=1;
	rep(i, 1, 12){
		if(qry(a))len++;
		else break;
		a*=10;
	}
	if(len>9){
		a=2;
		len=0;
		rep(i, 1, 12){
			if(!qry(a))len++;
			else break;
			a*=10;
		}
		printf("! 1");
		rep(i, 0, len)printf("0");
		fflush(stdout);
	}else{
		//cout<<len<<endl;
		rep(i, 0, len-1){
			int lo=0, hi=10;
			while(lo+1<hi){
			int mid=(lo+hi)>>1;
			(qry(g()*10+mid))?lo=mid:hi=mid;
		}
			ans.pb(lo);
		}
		int be=(sz(ans)?1:2);
		rep(i, be, 10){
			if(qry(g()*100+i*10)){
				ans.pb(i);
				break;
			}
		}
		printf("! ");
		rep(i, 0, sz(ans))printf("%d", ans[i]);
		fflush(stdout);
	}
	return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
// lld A[lim];

int main(){
    lld l = sc(), r = sc(), d = sc();
    prL(r / d - (l - 1) / d);   
    return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n;
long long a,b;
int main()
{
	cin>>n;
	for(int i=(int)sqrt((float)n);i>=1;i--)
	{
		if(n%i==0)
		{
			a = i 
			;b = n/i;
			break;
		}
	}
	cout<<(a-1)+(b-1);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}



Measured memory_bytes: 2104
N = int(input())
W = list(map(int, input().split()))

l = W[0]
r = sum(W[1:])
diff = abs(l - r)
for i in range(1, N):
    l += W[i]
    r -= W[i]
    new_diff = abs(l-r)
    if new_diff < diff:
        diff = new_diff
print(diff)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;

void solve2(){
    ll n;
    cin >> n;
    ll a[50];
    rep(i,n){
        cin >> a[i];
    }
    ll ans = 0;
    while(1){
        ll sum = 0LL;
        rep(i,n){
            sum += a[i]/n;
        }
        rep(i,n){
            ll k = a[i]/n;
            a[i] -= k*n;
            a[i] += sum-k;
        }
        ans += sum;
        if(sum==0LL){
            cout << ans << endl;
            exit(0);
        }
    }
    
}
void solve1(){
    ll k;
    cin >> k;
    int n = 50;
    vector<ll>a(n);
    int c = 0;
    while(k%50)k+=51,c++;
    //show(k);
    ll m = k/50LL+49;
    rep(i,n){
        if(i < c)a[i] = m-i-50-1;
        else a[i] = m;
    }
    cout << n << endl;
    rep(i,n-1){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int main(){
    solve2();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main() {
    ll N , T;
    cin >> N >> T;
    vector <ll> t(N);
    ll any = 0;
    for(ll i = 0; i < N; i++){
        cin >> t.at(i);
    }
    for(int i = 1; i < N; i++){
        if(t.at(i) - t.at(i - 1) >= T){
            any+=t.at(i) - t.at(i - 1) - T;
        }
    }
    cout << t.at(N - 1) - any + T << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=1,c=1;
    for (ll i=0;i<n;i++){
        ans*=3;
    }
    
    for (ll i=0;i<n;i++){
        if (a[i]%2==0){
            c*=2;
        }
    }
    cout << ans-c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << endl;
}

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

const int MAXN = 1010;
const int MAXM = 13;
int N, M;
int L[MAXN];
int dp[MAXN][1<<MAXM], prevj[MAXN][1<<MAXM];

int main() {
  while(cin >> N >> M && (N|M)) {
    for(int i = 0; i < N; ++i) {
      cin >> L[i];
    }
    memset(dp, 0, sizeof(dp));
    for(int j = 0; j < (1<<M); ++j) {
      dp[1][j] = (__builtin_popcount(j) == L[0]);
    }
    for(int i = 1; i < N; ++i) {
      for(int j = 0; j < (1<<M); ++j) {
	if(dp[i][j] == 0) continue;
	for(int k = 0; k < 2; ++k) {
	  int nj = (j | (k << M)) >> 1;
	  if(__builtin_popcount(nj) != L[i]) continue;
	  dp[i+1][nj] = min(2, dp[i+1][nj] + dp[i][j]);
	  prevj[i+1][nj] = j;
	}
      }
    }
    int b = -1;
    for(int j = 0; j < (1<<M); ++j) {
      if(dp[N][j]) b = j;
    }
    if(b != -1) {
      vector<int> v;
      int i, j;
      for(i = N, j = b; i > 1; --i) {
	int nj = prevj[i][j];
	v.push_back(j >> (M-1) & 1);
	j = nj;
      }
      for(int k = M-1; k >= 0; --k) {
	v.push_back(j >> k & 1);
      }
      reverse(v.begin(), v.end());
      for(int k = 0; k < v.size(); ++k) {
	cout << v[k];
      }
      cout << endl;
    } else {
      cout << "Goofy" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 65084
import std.stdio;
import std.string;
import std.array;

string card, next, tmp, s;
string[] queue;
int pos;
int[string] memo;
int[4] d = [-1, 1, 4, -4];


void main(){
	card = "01234567";
	queue ~= card;
	memo[card] = 0;
	solve();
	while (s = chomp(readln()), s) {
		s = replace(s, " ", "");
		writeln(memo[s]);
	}
}

void solve(){
	while (queue.length) {
		card = queue.front;
		queue.popFront();
		for (int i = 0; i < d.length; i++) {
			pos = cast(int)card.indexOf("0") + d[i];
			if (pos < 8 && pos >= 0 && !(pos == 4 && d[i] == 1) && !(pos == 3 && d[i] == -1)){
				tmp = card[pos..pos+1];
				next = replace(replace(replace(card, "0", "z"), tmp, "0") , "z", tmp);
				if(!(next in memo)){
					queue ~= next;
					memo[next] =  memo[card] + 1;
				}
			}
		}
	}
}

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

const int MAXN = 500005;

char s[MAXN];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	
	vector <int> v;
	
	int l = -1;
	for(int i = 0; i < n; i++){
		if(s[i] == '>'){
			v.push_back(i - l);
			l = i;
		}
	}
	v.push_back(n - l);
	
	long long res = 0;
	int p = -1;
	for(int i = (int)v.size() - 1; i >= 0; i--){
		res += 1LL * v[i] * (v[i] - 1) / 2;
		res += max(0, (p + 1) - (v[i] - 1));
		
		if(v[i] > 1)p = 0;
		else p = p + 1;
	}
	
	printf("%lld\n", res);
	
	return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n; cin >> n;
  vector<int> d(n);
  rep(i,0,n) cin >> d[i];
  sort(ALL(d));
  int p = n/2;
  cout << d[p]-d[p-1] << endl;
 }

Measured memory_bytes: 640
#include <iostream>

int main() {
    int a, b, c, d, e, f;
    std::cin >> a >> b >> c >> d >> e >> f;
    
    std::cout << ((a + b * 5 + c * 10 + d * 50 + e * 100 + f * 500) >= 1000) << std::endl;
}

Measured memory_bytes: 1164
#include <iostream>
#define ll long long
using namespace std;

ll gcd(ll a, ll b){
    if(a%b == 0){
        return b;
    }
    return gcd(b, a%b);
}

int main(void){
    ll n, x;
    cin >> n >> x;
    ll gc = gcd(n-x, x);
    cout << 3*(n-gc) << endl;
    return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }
template<typename T = i64>
void OUT(T& x) { cout << x << endl; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

#ifdef _DEBUG
signed Main()
#else
signed main()
#endif
{
	auto s = IN<string>();
	auto t = IN<string>();
	i64 n = SIZE(s), m = SIZE(t);

	vector<vector<i64>> is(26);
	REP(i, n) is[s[i] - 'a'].push_back(i);
	REP(i, n) is[s[i] - 'a'].push_back(i+n);
	i64 ans = 0;
	int p = 0;
	REP(i, m)
	{
		int c = t[i] - 'a';
		if (SIZE(is[c]) == 0)
		{
			puts("-1");
			return 0;
		}
		p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
		if (p >= n)
		{
			p -= n;
			ans += n;
		}
	}
	ans += p;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'

int main() {
    int n,max1,max2;
    long long suma=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                max1=__gcd(i,j);
                max2=__gcd(j,k);
                suma+=__gcd(max1,max2);
            }
        }
    }
    cout << suma << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int maxm = 1e5 + 10;
int n, m, g;
int ans[maxm], delta[maxm];
struct seg
{
	int l, r;
}a[maxn];
int main()
{
	scanf("%d%d", &n, &m);
	g = sqrt(m);
	for(int i = 1; i <= n; ++i)	
	{
		scanf("%d%d", &a[i].l, &a[i].r);
		--a[i].l;
	}
	for(int i = 1; i <= g; ++i)
	{
		for(int j = 1; j <= n; ++j)
			if(a[j].l / i != a[j].r / i)
				++ans[i];
	}
	for(int i = m / (g + 1); ~i; --i)
	{
		for(int j = 1; j <= n; ++j)
		{
			int l = max(g + 1, a[j].r / (i + 1) + 1) , r = i == 0 ? m : a[j].l / i;
			if(l > r) continue;
			delta[l]++;
			delta[r + 1]--;
		}
	}
	for(int i = g + 1; i <= m; ++i)
	{
		delta[i] += delta[i - 1];
		ans[i] = n - delta[i];
	}
	for(int i = 1; i <= m; ++i)
		printf("%d ", ans[i]);
	return 0;
}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if ((b - a) % 2 == 0)
        cout << (b - a) / 2;
    else
        cout << min(a - 1, n - b) + (b - a - 1) / 2 + 1;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
s = input().strip()
x,y = map(int,input().split())
AX = []
AY = []
flag = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        if flag==0:
            if cnt>0:
                AX.append(cnt)
                cnt = 0
            flag = 1
        else:
            if cnt>0:
                AY.append(cnt)
                cnt = 0
            flag = 0
if cnt>0 and flag==0:
    AX.append(cnt)
if cnt>0 and flag==1:
    AY.append(cnt)
Nx = sum(AX)
dpX = [[0 for _ in range(2*Nx+1)] for _ in range(len(AX)+1)]
dpX[0][Nx] = 1
if s[0]=="F":
    dpX[1][Nx+AX[0]] = 1
    for i in range(1,len(AX)):
        for j in range(2*Nx+1):
            if j+AX[i]<=2*Nx:
                dpX[i+1][j+AX[i]] = dpX[i+1][j+AX[i]] or dpX[i][j]
            if 0<=j-AX[i]:
                dpX[i+1][j-AX[i]] = dpX[i+1][j-AX[i]] or dpX[i][j]
else:
    for i in range(len(AX)):
        for j in range(2*Nx+1):
            if j+AX[i]<=2*Nx:
                dpX[i+1][j+AX[i]] = dpX[i+1][j+AX[i]] or dpX[i][j]
            if 0<=j-AX[i]:
                dpX[i+1][j-AX[i]] = dpX[i+1][j-AX[i]] or dpX[i][j]
Ny = sum(AY)
dpY = [[0 for _ in range(2*Ny+1)] for _ in range(len(AY)+1)]
dpY[0][Ny] = 1
for i in range(len(AY)):
    for j in range(2*Ny+1):
        if j+AY[i]<=2*Ny:
            dpY[i+1][j+AY[i]] = dpY[i+1][j+AY[i]] or dpY[i][j]
        if 0<=j-AY[i]:
            dpY[i+1][j-AY[i]] = dpY[i+1][j-AY[i]] or dpY[i][j]
if Nx==0 and x!=0 or Ny==0 and y!=0:
    print("No")
elif abs(x)>Nx or abs(y)>Ny:
    print("No")
elif dpX[len(AX)][Nx+x]==1 and dpY[len(AY)][Ny+y]==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 210220
H,W,K=map(int,input().split())
C=[input() for i in range(H)]
B=''.join(C).count('#')
from itertools import product
a=0
for p in product((0,1),repeat=H+W):
    b=B
    for h in range(H):
        for w in range(W):
            if C[h][w]=='#' and (p[h] or p[H+w]):
                b-=1
    if b==K:
        a+=1
print(a)

Measured memory_bytes: 9188
import java.io.PrintWriter
import java.util.*
import java.math.*

val pw = PrintWriter(System.out)


val end: Int = 4
fun dfs(i: Int, num: Int, x: List<Int>, formula: String): String {
    if(i == end) {
        if(num == 7) return formula + "=7"
        else return ""
    } else {
        val cx = x[i]
        val ansPlus = dfs(i+1, num+cx, x, formula+"+$cx")
        val ansMinus = dfs(i+1, num-cx, x, formula+"-$cx")
        return if(ansMinus.isEmpty()) ansPlus else ansMinus
    }
}

fun main(args: Array<String>) {
    val x = read()
    val xInt = x.map { it.toString().toInt() }

    println(dfs(1, xInt[0], xInt, "${xInt[0]}"))
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 33556
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> PII;
typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
typedef vector<long long> VLL; 
#define For(i,a,b) for(int i = (a); i < (b); ++i)
#define Rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const LL ML = 4e18;

void solve() {
    LL n;
    cin >> n;
    string res;
    while(n) {
        int p = (n - 1 + 26) % 26;
        res.push_back(char(p + 'a'));
        n = (n - 1) / 26; 
    }
    reverse(all(res));
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    //freopen("D:\\data_out.txt", "w", stdout);
    solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


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

int main(void){
	string s;
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(),a.end());
	cout << a[2]*10+a[1]+a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];


int main(){
  ll n,ans=0;cin>>n;
  vll a(n);
  rep(i,0,n){
    cin>>a[i];
  }
  
  rep(i,0,n-1){
    if(a[i]==i+1){
      swap(a[i],a[i+1]);
      ans++;
    }
  }
  if(a[n-1]==n){
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4024
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>

using namespace std;


void Solution()
{
    long i,j,k;
    
    string s[9]; //use string instead of int type
    
    for(int i=0; i<9; i++)
    {
        cin>>s[i];
    }
    
    i = j = k = 0;
    
    cout<<"R";
    
    j++;
    
    for(;;) // infinite loop
    {
        //algorithm
        if(k == 0 && i > 0 && s[i - 1][j] == '1')
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 0 && s[i][j] == '1')
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 0 && i < 8 && s[i + 1][j] == '1')
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        else if(k == 0)
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 1 && s[i][j] == '1')
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 1 && i < 8 && s[i + 1][j] == '1')
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        else if(k == 1 && j > 0 && s[i][j - 1] == '1')
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 1)
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 2 && i < 8 && s[i + 1][j] == '1')
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        else if(k == 2 && j > 0 && s[i][j - 1] == '1')
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 2 && i > 0 && s[i - 1][j] == '1')
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 2)
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 3 && j > 0 && s[i][j - 1] == '1')
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 3 && i > 0 && s[i - 1][j] == '1')
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 3 && s[i][j] == '1')
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 3)
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        
        if(i == 0 && j == 0)
        {
            break;
        }
    }
    
    cout<<endl;
    
}

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

Measured memory_bytes: 1180
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
	Scanner scan =new Scanner(System.in);
	int N=scan.nextInt();
	long num[]=new long[N];
	long answer=1;
	long max =1000000000000000000L;
		for(int i=0;i<N;i++) {
			num[i]=scan.nextLong();
		}
		Arrays.sort(num);
		for(Long tmp:num) {
			if(tmp==0) {
				answer=0;
				break;
			}else if(tmp<=(max/answer)) {
				answer*=tmp;
			}else {
				answer =-1;
				break;
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 61656
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, R;

	cin >> N >> R;

	if(N < 10) {
		cout << R + 100 * (10 - N) << endl;
	} else {
		cout << R << endl;
	}
}

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

const int maxn = 305;

int N, M;
int A[maxn][maxn];
int ptr[maxn];
int cnt[maxn], erased[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j)
			cin >> A[i][j];
	}
	for (int i = 1; i <= N; ++i) {
		ptr[i] = 1;
		++cnt[A[i][1]];
	}
	int ans = *max_element(cnt + 1, cnt + M + 1);
	for (int x = 1; x < M; ++x) {
		int mx = max_element(cnt + 1, cnt + M + 1) - cnt;
		// erase mx
		erased[mx] = 1;
		for (int i = 1; i <= N; ++i) {
			--cnt[A[i][ptr[i]]];
			while (erased[A[i][ptr[i]]])
				++ptr[i];
			++cnt[A[i][ptr[i]]];
		}
		ans = min(ans, *max_element(cnt + 1, cnt + M + 1));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 640
n,k=map(int, input().split())
x=list(map(int, input().split()))
zi=0
for xi in x:
    if xi>=0:
        break
    zi+=1

xm=[0]
if zi<len(x) and x[zi]==0:
    xp=[]
else:
    xp=[0]

xm.extend(reversed(x[:zi]))
xp.extend(x[zi:])

ans=float('inf')
for i in range(k):
    if i<len(xm) and k-i<len(xp):
        ans=min(xm[i]*2*(-1) + xp[k-i], ans)
    if i<len(xp) and k-i<len(xm):
        ans=min(xp[i]*2 + xm[k-i]*(-1), ans)
if len(x)==1 and x[0]==0:
    ans=0
print(ans)

Measured memory_bytes: 14480
import itertools

n=int(input())
c=0
for i in range(len(str(n))+1):
      for j in list(itertools.product((3,5,7),repeat=i)):
            if (3 in j) and (5 in j) and (7 in j):
                  if n >=int((''.join(list(map(str,j))))):
                        c+=1
print(c)

Measured memory_bytes: 6260
NT = list(map(int, input().split()))
N = NT[0]
T = NT[1]
l = []
for i in range(N):
    l.append(list(map(int, input().split())))

lf = list(filter(lambda x: x[1] <= T, l))

if(len(lf) == 0):
    print('TLE')
else:
    ls = sorted(lf, key=lambda x: x[0])
    print(ls[0][0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main (){
  int A , B , C ;
  cin>>A>>B>>C;
  bool answer = false;
  if(A==5 && B==7){
    if(C==5){
      answer = true ;
    }
  }
  if(A==5 && B==5){
    if(C==7){
      answer = true ;
    }
  }
  if(A==7 && B==5){
    if(C==5){
      answer = true ;
    }
  }
  if(answer){
    cout<<"YES"<<endl;
  }
  if(!answer){
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   bool f=true;
   int x,y;
   cin >> x >> y;

   while(f){
      int ans =0;
      if (x==0 && y==0){
         f=false;
         break;
      }
      else{
         for (int i=1;i <= x;i++){
            for (int j=i+1;j <= x;j++){
               for (int k=j+1;k <= x;k++){
                  if (i==j || k==j || i==k ) continue;
                  else if (i+j+k==y) {
                     //printf("(i,j,k) = (%d ,%d ,%d)\n",i,j,k);
                     ans++;
                  }
               }
            }
         }
      }
      cout << ans << endl;
      cin >> x >> y;
   }
   return 0;
}




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

int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
    int N, Q;
    std::string s;

    //入力
    std::cin >> N >> Q;
    std::cin >> s;

    std::vector<std::pair<char, char>> spells(Q);
    for (auto& i : spells)std::cin >> i.first >> i.second;
    //入力終わり

    //二分探索書くの面倒だから標準ライブラリに任せたいがための配列
    std::vector<int> arr(N);
    for (int i = 0; i < N; ++i)arr[i] = i;

    //左に落ちる：-1
    //右に落ちる： 1
    //マスに残る： 0
    auto func = [&](int v) {
        for (const auto& i : spells) {
            if (v < 0 || N <= v)break;
            if (s[v] == i.first)v += (i.second == 'L' ? -1 : 1);
        }
        if (v < 0)return -1;
        if (N <= v)return 1;
        return 0;
    };

    //左に落ちるゴーレムの中で一番右のやつ
    auto itr = std::partition_point(arr.cbegin(), arr.cend(), [&](int v) { return func(v) < 0; });
    //右に落ちるゴーレムの中で一番左のやつ
    auto itr2 = std::partition_point(arr.crbegin(), arr.crend(), [&](int v) { return func(v) > 0; });

    //上の2者の距離を出せばいい
    std::cout << std::distance(itr,itr2.base()) << std::endl;
}

Measured memory_bytes: 1812
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  int f = 1; 
  for(int i = 0; i < n; i += 2)
    if(s[i] == 'L')
      f = 0;
   
  for(int i = 1; i < n; i += 2)
    if(s[i] == 'R')
      f = 0;
  if(f)
    cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <memory>
#include <cassert>

using namespace std;

int main()
{

    int A, B, C;

    cin>>A>>B>>C;

    if(A+B<C)
        cout<<A+B+1+B<<endl;
    else
        cout<<C+B<<endl;

    return 0;
}

Measured memory_bytes: 256