akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int k = in.nextInt();
			int w[] = in.nextIntArray(n);
			int l = 0, r = 100000 * 10000;
			int p = 0 ;
			while (r - l > 1) {
				p = (l + r) / 2;
				int v = MathUtils.allocateNum(w, p, k);
				if (v >= n) {
					r = p;
				} else if (v < n) {
					l = p;
				}
			}
			System.out.println(r);
		}

	}

	static class MathUtils {
		// 最大積載量Pのトラックk台で何個の荷物を積めるか？
		public static int allocateNum(int[] w, int p, int k) {
			int i = 0;
			for (int j = 0; j < k; j++) {
				int sum = 0;
				while ((sum + w[i]) <= p) {
					sum = sum + w[i];
					i++;
					if (i == w.length) return w.length;
				}
			}
			return i;
		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



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

int main() {
  ll X;
  cin >> X;
  vector<ll> pent;
  for (ll n = 0; n < 300; n++) {
    pent.push_back(powl(n,5));
  }
  
  for (ll i = 0; i < 300; i++) {
    if (pent[i]*2 < X) continue;
    for (ll j = 0; j < i; j++) {
      if (pent[i]-pent[j] == X) {
        cout << i << " " << j << endl;
        return 0;
      }
      if (pent[i]+pent[j] == X) {
        cout << i << " -" << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define mp make_pair
#define fir first
#define sec second
#define pb push_back
#define gc getchar()
#define lint long long
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
#define wrong return !printf("-1\n")
#define N 100010
using namespace std;
typedef pair<int,int> pii;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
struct P{
	lint d;int id;
	inline bool operator<(const P &p)const{return d>p.d;}
}p[N];int n;
vector<int> g[N];
int us[N],vs[N],sz[N];
lint d[N];map<lint,int> sv;
int getdrt(int x,int l,int rt)
{
	d[rt]+=l;
	Rep(i,g[x]) getdrt(g[x][i],l+1,rt);
	return 0;
}
int getd(int x)
{
	Rep(i,g[x]) d[g[x][i]]=d[x]+n-2*sz[g[x][i]],getd(g[x][i]);
	return 0;
}
int main()
{
	n=inn();
	for(int i=1;i<=n;i++) scanf("%lld",&p[i].d),p[i].id=i,sv[p[i].d]=i;
	for(int i=1;i<=n;i++) sz[i]=1;
	sort(p+1,p+n+1);//from big to small
	for(int i=1;i<n;i++)
	{
		int x=p[i].id;
		lint dlt=n-2*sz[x];
		if(dlt<=0) wrong;
		if(!sv.count(p[i].d-dlt)) wrong;
		int fa=sv[p[i].d-dlt];
		us[i]=fa,vs[i]=x,sz[fa]+=sz[x];
	}
	for(int i=1;i<n;i++) g[us[i]].pb(vs[i]);
	int rt=p[n].id;getdrt(rt,0,rt),getd(rt);
	for(int i=1;i<=n;i++)
		if(d[p[i].id]!=p[i].d) wrong;
	for(int i=1;i<n;i++) printf("%d %d\n",us[i],vs[i]);
}

Measured memory_bytes: 18944
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x=INT()
    year=0
    temp=100
    while temp<x:
        temp=int(temp*1.01)
        year+=1
    print(year)
if __name__ == '__main__':
    do()

Measured memory_bytes: 9192
#include <cstdio>
#include <cstring>
#include <algorithm>
const int MAXN = 3000 + 10;
const int MOD = 1e9 + 7;

int n, q;
int a[MAXN];
int f[MAXN][MAXN];
int last[MAXN][MAXN];
namespace {
  inline int add(int x) { return x >= MOD ? x - MOD : x; }
  inline int mul(int x, int y) { return 1ll * x * y % MOD; }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  static int pwr[MAXN];
  pwr[0] = 1;
  for (int i = 1; i <= q; i++) pwr[i] = mul(pwr[i - 1], 2);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i] > a[j]) f[i][j] = 1;
      last[i][j] = q;
    }
  }

  while(q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    // x, y => y, x
    int tmp1 = mul(f[x][y], pwr[last[x][y] - q - 1]),
      tmp2 = mul(f[y][x], pwr[last[y][x] - q - 1]);
    f[x][y] = add(tmp1 + tmp2);
    f[y][x] = add(tmp2 + tmp1);
    last[x][y] = last[y][x] = q;

    for (int i = 1; i <= n; i++) {
      if (i == x || i == y) continue;
      int tmp1 = mul(f[x][i], pwr[last[x][i] - q - 1]),
        tmp2 = mul(f[y][i], pwr[last[y][i] - q - 1]);
      f[x][i] = add(tmp1 + tmp2);
      f[y][i] = add(tmp1 + tmp2);

      
      tmp1 = mul(f[i][x], pwr[last[i][x] - q - 1]);
      tmp2 = mul(f[i][y], pwr[last[i][y] - q - 1]);
      
      f[i][x] = add(tmp2 + tmp1);
      f[i][y] = add(tmp1 + tmp2);

      last[x][i] = last[y][i] = last[i][x] = last[i][y] = q;
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans = add(ans + mul(f[i][j], pwr[last[i][j]]));
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 70912
#include <iostream>
using namespace std;
void bsort(int *n1, int *n2, int *n3)
{
	if(*n1 > *n2) {
	int tmp = *n1;
	*n1 = *n2;
	*n2 = tmp;
	}
	if(*n1 > *n3){
	int tmp = *n1;
	*n1 = *n3;
	*n3 = tmp;
	}
	if(*n2 > *n3){
	int tmp = *n2;
	*n2 = *n3;
	*n3 = tmp;
	}
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bsort(&a, &b, &c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}



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

int main(){
    int n;
    cin >> n;

    int arr[n];
    int tmp = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        ans += p;
        tmp = max(tmp,p);
    }

    cout << ans - tmp/2;
}

Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int M = int.Parse(s[1]);
        int X = int.Parse(s[2]);
        int[] A = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        int r = 0;
        int l = 0;
       
        bool[] gates = new bool[N + 1];
        for(int b = 0;b < gates.Length;b++){
            gates[b] = false;
        }
        foreach(int i in A){
            gates[i] = true;
        }
        for(int x = 0;x < N + 1;x++){
            if(x < X && gates[x] == true){
                l++;
            }else if(X < x && gates[x] == true){
                r++;
            }
        }
       
        Console.WriteLine(Math.Min(r,l));
    }
}


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

int main() {
    int N;
    cin >> N;
    long long i_2 = 2;
    long long i_1 = 1;
    long long ans = 1;
    for (int i = 0; i < N-1; ++i) {
        ans = i_1 + i_2;
        long long n_i_1 = i_1;
        i_1 = ans;
        i_2 = n_i_1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    int ans = h[k-1] - h[0];
    for(int i=0;i<=n-k;i++){
        int diff = h[i+k-1]-h[i];
        ans = min(ans, diff);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3736
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define num 1e9
#define root 10000
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)
#define i(n) insert(n)

using namespace std;

int main()
{
    string a;
    cin>>a;
    int x=0;
    forll(i,0,a.size()-1,1)
    {
        x+=(a[i]-'0');
    }
    if(x%9==0){cout<<"Yes\n";}
    else{cout<<"No\n";}
}


Measured memory_bytes: 3760
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 
 
using namespace std;
 
#define len(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i; 
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.x >> a.y;
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.x << " " << a.y;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;
}
 
const int INF = 1e18, MAXN = 1e4 + 10, MOD = 1e9 + 7, BASE = 37;

void solve() {
    int a, b;
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
    	cout << a * b << endl;
    }
    else {
    	cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll n,a,b,d,ans=0,cnt=0,x=0,dmin=100;
	cin>>n;
	REP(i,0,n-1)
	{
		ll x;
		cin>>x;
		d=0;
		while(x%2==0)
		{
			x=x/2;
			d++;
		}
		dmin=min(dmin,d);
	}
	cout<<dmin;
}

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

int main() {

  char s[10];
  cin >> s;
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
  else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) cout << "Yes" << endl;
  else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define int long long

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

const int maxn = 1e5+1e2;

int a[maxn];
int n,m;
int ans;

signed main()
{ 
  n=read(),m=read();
  for (long long i=1;i*i<=m;i++)
  {
  	 if (n*i<=m) 
  	   if (m%i==0) ans=max(ans,i);
  	if (m%i==0 && n*(m/i)<=m)
  	  ans=max(ans,m/i);
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
using System;

class MyCards
{
    int n;
    bool[,] cards;
    //?????£????????????????????????????????????
    public void CheckCards()
    {
        for(int i =0;i<4;i++)
        {
            for(int j =0;j<13;j++)
            {
                if(cards[i,j]==false)
                {
                    if(i==0)
                        Console.WriteLine("S {0}",j+1);
                    else if(i==1)
                        Console.WriteLine("H {0}",j+1);
                    else if(i==2)
                        Console.WriteLine("C {0}",j+1);
                    else if(i==3)
                        Console.WriteLine("D {0}",j+1);
                }
            }
        }
    }
    //?????£?????????????????????true?????????
    public void HaveCards()
    {
        for (int i = 0; i < n; i++)
        {
            //cards[0,]=S,[1,]=H,[2,]=C,[3,]=D
            string str = Console.ReadLine();
            string[] s = str.Split(' ');
            int num = int.Parse(s[1]);
            if (s[0] == "S")
                cards[0, num - 1] = true;
            else if (s[0] == "H")
                cards[1, num - 1] = true;
            else if (s[0] == "C")
                cards[2, num - 1] = true;
            else if (s[0] == "D")
                cards[3, num - 1] = true;

        }
    }
    //??¨??????false?????????
    public MyCards()
    {
        cards = new bool[4, 13];
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 13; j++)
            {
                cards[i, j] = false;
            }
        }
        n = int.Parse(Console.ReadLine());
        HaveCards();
    }
}

class Program
{
    static void Main()
    {
        MyCards mc = new MyCards();
        mc.CheckCards();
    }
}

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

using namespace std;

int main(){
	string s;
	cin>>s;
	int n=(int)s.size();
	for(int i=0;i<n;i++){
		if(s[i]=='9')s[i]='1';
		else s[i]='9';
	}
	cout<<s;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

int main() {
	int n; cin >> n;
	map<int, int> m1, m2;
	pair<int, int> fmax1, fmax2, smax1, smax2;
	for (int i = 0; i < n; ++i) {
		int v; cin >> v;
		if (i & 1) {
			m2[v]++;
			if (m2[v] > fmax2.second) fmax2 = { v,m2[v] };
			else if (m2[v] > smax2.second) smax2 = { v,m2[v] };
		} else {
			m1[v]++;
			if (m1[v] > fmax1.second) fmax1 = { v,m1[v] };
			else if (m1[v] > smax1.second) smax1 = { v,m1[v] };
		}
	}
	int ans = n;
	if (fmax1.first != fmax2.first) ans -= fmax1.second + fmax2.second;
	else ans -= max(fmax1.second + smax2.second, smax1.second + fmax2.second);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>

int main() {
  int n, x;
  std::cin >> n >> x;
  int const len = n*2 - 1;

  if (x == 1 || x == len) {
    std::cout << "No" << std::endl;
    return 0;
  }

  std::cout << "Yes" << std::endl;
  for (int i=0; i<len; i++) {
    auto const j = (n + x - 1 + i) % len;
    std::cout << (j+1) << '\n';
  }

  return 0;
}



Measured memory_bytes: 1536
n,m=map(int,input().split())
a=[]
c=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(m):
    c.append(list(map(int,input().split())))

for k in range(n):
    tmp=[]
    for j in range(m):
        tmp.append(abs(a[k][0]-c[j][0])+abs(a[k][1]-c[j][1]))
    print(tmp.index(min(tmp))+1)



Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
using namespace std;

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

int N, C, X;
int D[30][39], t[3][31];

int main(void){
    
    cin >> N >> C;
    rep(i,C)rep(j,C) scanf("%d", &D[i][j]);
    rep(i,N)rep(j,N) scanf("%d", &X), t[(i+j)%3][X-1]++;
    
    int res = 1<<30;
    rep(i,C)rep(j,C)if(i!=j)rep(k,C)if(i!=k&&j!=k){
        int tt = 0;
        rep(l,C) tt += D[l][i] * t[0][l];
        rep(l,C) tt += D[l][j] * t[1][l];
        rep(l,C) tt += D[l][k] * t[2][l];
        if(res>tt) res = tt;
    }
    
    cout << res << endl;
}


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


int main() {
	int s;
	int i;
	int j;
  	int k;
	int n;
	int a[3010];
	long long np[3010][3010];

	cin >> n >> s;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < s+1; j++) {
			np[i][j]=0;
		}
	}
	np[0][0]=2;
	np[0][a[0]]=1;
  	for (i = 1; i < n; i++) {
		for (j = 0; j <= s; j++) {
			np[i][j]=2*np[i-1][j];
		}
		for (j = 0; j <= s-a[i]; j++) {
			k=j+a[i];
			np[i][k]=np[i][k]+np[i-1][j];
		}
		for (j = 0; j <= s; j++) {
			np[i][j]=np[i][j] % 998244353;
		}
    }
	cout << np[n-1][s];
	return 0;
}

Measured memory_bytes: 74204
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

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

    int cnt = 0;
    ll ans = 0;
    for (auto c: s)
    if (c == 'B')
        ++cnt;
    else
        ans += cnt;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string.h>

#define MAX_LINE 8
#define MAXA_DATA 50

using namespace std;

// プロトタイプ宣言
void searchString(string box);

// main関数
int main() {
    int count = 0;
    int max = MAX_LINE * MAXA_DATA;
    char str[8];
    string box;
    for (int i = 0; i < max; i++) {
        cin >> str;
        box.append(str);
        count++;
        // 8行ごとにチェック
        if(count%MAX_LINE == 0){
            searchString(box);
            box = "";
        }
    }
}

// 文字列チェック
void searchString(string box){
    string A("1100000011");
    string B("1000000010000000100000001");
    string C("1111");
    string D("1000000110000001");
    string E("11000000011");
    string F("100000001100000001");
    string G("110000011");
    
    // find関数は文字列がみつからなかったときにnposを返す
    if (box.find(A) != std::string::npos) {
        cout << "A" << endl;
    }
    else if(box.find(B) != std::string::npos) {
        cout << "B" << endl;
    }
    else if(box.find(C) != std::string::npos) {
        cout << "C" << endl;
    }
    else if(box.find(D) != std::string::npos) {
        cout << "D" << endl;
    }
    else if(box.find(E) != std::string::npos) {
        cout << "E" << endl;
    }
    else if(box.find(F) != std::string::npos) {
        cout << "F" << endl;
    }
    else if(box.find(G) != std::string::npos) {
        cout << "G" << endl;
    }
}


Measured memory_bytes: 3100
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    if len(S)==2:
        print(S)
    else:
        print(''.join(list(reversed(S))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
$N=<>;
$i=1;
$_[2]=1;
for(<>){
	/ /;
	if($i==$`){
		$i=$'
	}elsif($i==$'){
		$i=$`
	}
	if($_[$`]!=$_[$']){
		@_[$`,$']=@_[$',$`]
	}
	$_[$i-1]=$_[$i+1]=1
}
print~~grep$_[$_]||$_==$i,1..$N


Measured memory_bytes: 16128
#include <iostream>
#include <vector>
#include <cstring>

const int N = 100 + 1;

std::vector<int> G[N];
int vis[N];

bool go(int v) {
  bool f = false;
  vis[v] = 1;
  for (auto &d : G[v]) {
    if (vis[d] == 1) return true;
    if (vis[d] == 2) continue;
    f |= go(d);
  }
  vis[v] = 2;
  return f;
}

int main() {
  int n, e;
  while (std::cin >> n >> e) {
    for (int i = 0; i < N; ++i) G[i].clear();
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < e; ++i) {
      int s, t;
      std::cin >> s >> t;
      G[s].emplace_back(t);
    }
    bool flag = false;
    for (int i = 0; i < n; ++i) {
      if (vis[i] == 2) continue;
       flag |= go(i);
    }
    std::cout << flag << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <int>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
ll mod=1e9+7;
bool is_prime(int n)
{
    if(n==2)
        return true;
    if(n%2==0||n<2)
        return false;
    for(int i=3; i<=sqrt(n); i+=2)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=(power(n,k/2))%mod;
    sq=(sq*sq)%mod;
    if(k%2==1)
        sq=(sq*n)%mod;
    return sq%mod;
}
void low(char &c){
c=tolower(c);
}
void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        cout << 2 << " ";
        n = n/2;
    }

    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    if (n > 2)
        cout << n << " ";
}

#include <iostream>
using namespace std;
void fast();
int arr[100005];
map <int,int> M;
int main() {
//fast();
int n,m,ch;
string s;
cin >> n >> m;
int AC=0,WA=0;
loop(m){
    cin >> ch >> s;
    if(arr[ch]!=-1){
       if(s=="WA"){
            arr[ch]++;
        }else{
            AC++;
            WA += arr[ch];
            arr[ch]=-1;
        }
    }

}
cout << AC << " " << WA;
}





void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	bool p[1000000] = {};
	p[0] = p[1] = true;
	rep(i,1001) {
		if(!p[i]) {
			for(int j = 2*i; j<1000000; j+=i) {
				p[j] = true;
			}
		}
	}
	int n;
	while(cin>>n,n) {
		int cnt = 0;
		rep(i,n/2+1) {
			if(!p[i] && !p[n-i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2140
#include <stdio.h>

int main(void)
{
  unsigned long debt;
  int week, i;
  debt = 100000;

  scanf("%d", &week);

  for(i = 0; i < week; i++){
    debt = (debt * 105) / 100;
    if(debt % 1000)
      debt = (debt / 1000) + 1;
    else
      debt = debt / 1000;
    debt = debt * 1000;
  }

  printf("%lu\n", debt);

  return(0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
unordered_map<int64_t, bool> M;
vector<int64_t> v;
int st[15], n;
inline void Back(int k, int64_t nr) {
    if (M.find(nr) == M.end())
        v.emplace_back(nr), M[nr] = true;
    if (k <= 10)
        for (int i = max(st[k-1] - 1, 0); i <= min(st[k-1] + 1, 9); ++i) {
            st[k] = i;
            Back(k + 1, nr * 10LL + i);
        }
}
int main() {
    DAU
    for (int i = 2; i < 9; ++i) {
        st[0] = i;
        Back(1, 0);
    }
    sort(v.begin(), v.end());
    cin >> n;
    cout << v[n];
    PLEC
}


Measured memory_bytes: 10044
N=int(input())
dp=[[0]*(N+1) for i in range(N+1)]
dp[0][0]=1
MOD=10**9+7
for i in range(N):
    s=input()
    for j in range(i+1):
        if s=="-":
            nj=j
            dp[i+1][nj]+=dp[i][j]
            dp[i+1][nj]%=MOD
        elif s=="U":#実際には下がる
            nj=j+1
            dp[i+1][nj]+=dp[i][j]
            dp[i+1][nj]%=MOD

            nj=j
            x=j
            dp[i+1][nj]+=dp[i][j]*x
            dp[i+1][nj]%=MOD
        elif s=="D":#実際には上がる
            nj=j
            x=j
            dp[i+1][nj]+=dp[i][j]*x
            dp[i+1][nj]%=MOD

            if nj==0:
                continue
            nj=j-1
            x=j*j
            dp[i+1][nj]+=dp[i][j]*x
            dp[i+1][nj]%=MOD
print(dp[N][0])



Measured memory_bytes: 6160
#include<bits/stdc++.h>
using namespace std;
#define tpl  tuple<int, int, int>
#define mt   make_tuple
#define LIM  100000


int n, dp[LIM+5][4], vis[LIM+5][4];
vector<tpl> v;

int f(int pos, int k){
    if(pos >= n) return 0;
    if(vis[pos][k]) return dp[pos][k];
    vis[pos][k] = 1;
    int ans;
    if(k == 0) ans = get<0>(v[pos]) + max(f(pos+1, 1), f(pos+1, 2));
    else if(k == 1) ans = get<1>(v[pos]) + max(f(pos+1, 0), f(pos+1, 2));
    else ans = get<2>(v[pos]) + max(f(pos+1, 0), f(pos+1, 1));

    return dp[pos][k] = ans;
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        v.push_back(mt(a, b, c));
    }
    int ans = f(0, 0);
    memset(dp, 0, sizeof dp);
    memset(vis, 0, sizeof vis);
    ans = max(ans, f(0, 1));
    memset(dp, 0, sizeof dp);
    memset(vis, 0, sizeof vis);
    ans = max(ans, f(0, 2));

    printf("%d\n", ans);
}


Measured memory_bytes: 12576
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
int main()
{
   int n;
  cin>>n;
  std::vector<int> v(n);
  for(int i=0;i<n;i++)
  cin>>v[i];
  vector<int>dp(n,0);
dp[0]=0;
dp[1]=abs(v[1]-v[0]);
for(int i=2;i<n;i++)
	dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));

 cout<<dp[n-1];
 return 0;
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A_sum=0
for i in range(N):
   if A[i]>B[i]:
      A_sum+=A[i]-B[i]
   elif A[i]<B[i]:
      A_sum-=(B[i]-A[i])//2
if A_sum<=0:
   print("Yes")
else:
   print("No")

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long INTEGER;
typedef double FLOAT;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

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

int main()
{
entry:;

  int w, h; cin >> w >> h;
  if (!w && !h) return 0;

  int f[h][w];
  int ci, cj;
  rep (i, h) {
    string s; cin >> s;
    rep (j, s.size()) {
      if (s[j] == '.') {
        f[i][j] = 1;
      } else if (s[j] == '@') {
        f[i][j] = 1;
        ci = i;
        cj = j;
      } else {
        f[i][j] = 0;
      }
    }
  }

  stack<pair<int,int>> s;
  s.push(cons(ci, cj));

  int ans = 0;
  while (!s.empty()) {
    pair<int, int> x = s.top(); s.pop();
    if (f[car(x)][cdr(x)] == 0) continue;
    f[car(x)][cdr(x)] = 0;
    ++ans;

    if (car(x) > 0) s.push(cons(car(x) - 1, cdr(x)));
    if (cdr(x) > 0) s.push(cons(car(x), cdr(x) - 1));
    if (car(x) < h - 1) s.push(cons(car(x) + 1, cdr(x)));
    if (cdr(x) < w - 1) s.push(cons(car(x), cdr(x) + 1));

  }

  cout << ans << endl;

  goto entry;

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI v(n);
    REP(i,0,n) cin >> v[i];
    VVI cnt(2, VI(100001));
    for (int i = 0; i < n; i += 2) cnt[0][v[i]]++;
    for (int i = 1; i < n; i += 2) cnt[1][v[i]]++;
    auto it0 = max_element(all(cnt[0])) - cnt[0].begin();
    auto it1 = max_element(all(cnt[1])) - cnt[1].begin();
    //dump(it0);
    //dump(it1);
    int se0 = 0, se1 = 0;
    REP(i,0,100000) if (cnt[0][i] > se0 && i != it0) se0 = cnt[0][i]; 
    REP(i,0,100000) if (cnt[1][i] > se1 && i != it1) se1 = cnt[1][i]; 
    if (it0 != it1) cout << n - *max_element(all(cnt[0])) - *max_element(all(cnt[1])) << endl;
    else cout << n - *max_element(all(cnt[0])) - max(se0, se1) << endl;
}

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

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

const int mxN = 2e5 + 5;
int a[mxN];

int main() {
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a + n);
	long long answer = 0;
	for(int i = n - 1; ~i; --i) {
		if(k) {
			--k;
			continue;
		}
		answer += a[i];
	}
	cout << answer;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define ll long long
#define ld long double

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()

#define endl '\n'
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double PI=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
int ddx[5] = {2,1,0,-1,-2};
int ddy[5] = {2,1,0,-1,-2};
 
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  map<pii,ll> mp;
  rep(i,n){
    double a;
    cin >> a;
    ll na = (llround)(a*1e9);
    int two = 0, five = 0;
    while(na%2==0){
      two++;
      na/=2;
    }
    while(na%5==0){
      five++;
      na/=5;
    }
    mp[pii(two,five)]++;
  }
  ll ans = 0;
  for(auto p1:mp){
    for(auto p2:mp){
      if(p1.fi.fi+p2.fi.fi >= 18 && p1.fi.se+p2.fi.se>=18){
        if(p1==p2){
          ans += p1.se*(p1.se-1);
        }
        else{
          ans += p1.se*p2.se;
        }
      }
    }
  }
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 3792
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

extern inline char gc() {
    static char RR[23456], *S = RR + 23333, *T = RR + 23333;
    if(S == T) fread(RR, 1, 23333, stdin), S = RR;
    return *S ++;
}
inline int read() {
    int p = 0, w = 1; char c = gc();
    while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
    while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
    return p * w;
}

#define ri register int
int n, n2, n4, flag;

int main() {
    n = read();
    for(ri i = 1; i <= n; i ++) {
        int x = read();
        if(x % 4 == 0) n4 ++;
        else if(x % 2 == 0) n2 ++;
    }
    n -= n2;
    if(n & 1) {
        if(n2) flag = (n4 > n / 2);
        else flag = (n4 >= n / 2);
    }
    else flag = (n4 >= n / 2);
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};
struct wolf{
	int m[10][10];
	wolf(){for(int i=0;i<10;i++)for(int j=0;j<10;j++)m[i][j]=0;}
};
int st[10][10];
char str[2];
int a,b;
int ret;
void solve(int t,wolf w){
	//printf("%d\n",t);
	//fflush(stdout);
	if(t>=ret)return;
	bool ok=true;
	for(int i=0;i<b;i++)
		for(int j=0;j<a;j++)
			if(w.m[i][j]!=w.m[0][0])ok=false;
	if(ok){
		ret=t;
		return;
	}
	for(int i=1;i<4;i++){
		if(w.m[0][0]==i)continue;
		wolf D=w;
		queue<pair<int,int> >Q;
		Q.push(make_pair(0,0));
		D.m[0][0]=i;
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop();
			for(int j=0;j<4;j++)
				if(0<=row+dx[j]&&row+dx[j]<b&&0<=col+dy[j]&&col+dy[j]<a&&w.m[0][0]==D.m[row+dx[j]][col+dy[j]]){
					Q.push(make_pair(row+dx[j],col+dy[j]));
					D.m[row+dx[j]][col+dy[j]]=i;
				}
		}
		solve(t+1,D);
	}
}
int main(){
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++){
				scanf("%s",str);
				if(str[0]=='R')st[i][j]=1;
				if(str[0]=='G')st[i][j]=2;
				if(str[0]=='B')st[i][j]=3;
			}
		ret=a+b;
		wolf S;
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++)
				S.m[i][j]=st[i][j];
		for(int i=0;;i++){
			ret=i+1;
			solve(0,S);
			if(ret<=i)break;
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	LLONG X, K, D; cin >> X >> K >> D;
	X = llabs(X);
	LLONG r = X / D;
	if (K < r)
	{
		cout << X - K * D << endl;
	}
	else
	{
		K -= r;
		X %= D;
		K %= 2;
		if (K == 0)
		{
			cout << X << endl;
		}
		else
		{
			cout << llabs(X - D) << endl;
		}
	}
}


Measured memory_bytes: 3632
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,dist[205][205]={},a,b,c,r,R[10]={},ans=INF,cnt;
  cin >> n >> m >> r;
  for(int i=0; i<r; i++) {
    cin >> R[i];
    R[i]--;
  }
  sort(R,R+r);
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      if(i!=j) {
        dist[i][j]=INF;
      }
    }
  }
  for(int i=0; i<m; i++) {
    cin >> a >> b >> c;
    a--,b--;
    dist[a][b]=min(dist[a][b],c);
    dist[b][a]=min(dist[b][a],c);
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      for(int k=0; k<n; k++) {
        if(i!=j&&i!=k&&j!=k) {
          dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
        }
      }
    }
  }
  do{
    cnt=0;
    for(int i=0; i<r-1; i++) {
      cnt+=dist[R[i]][R[i+1]];
    }
    ans=min(ans,cnt);
  }while(next_permutation(R,R+r));
  cout << ans << endl;
}



Measured memory_bytes: 640
s=int(input())
count=2
num=s
collatz_list=[s]
while True:
    if num%2==0:
        num=num//2
    else:
        num=3*num+1
    if num in collatz_list:
        print(count)
        exit()
    else:
        collatz_list.append(num)
        count+=1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;cin>>a>>b>>c>>d;
    string ans="No";
    if(abs(a-c)<=d){
        ans="Yes";
    }
    if(abs(a-b)<=d && abs(b-c)<=d){
        ans="Yes";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=['a']*n
for i in range(m):
    s,c=map(str,input().split())
    s=int(s)
    s-=1
    if a[s]!='a':
        if a[s]!=c:
            print(-1)
            exit()
    else:
        a[s]=c
for i in range(n):
    if a[i]=='a':
        if n>1 and i==0:
            a[i]='1'
        elif i==0:
            a[i]='0'
        else:
            a[i]='0'
ans=''.join(a)
if len(str(int(ans)))!=n:
    print(-1)
else:
    print(int(ans))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;

    lint c[10][10] = {};

    for (int i = 1; i <= n; i++) {
        string di = to_string(i);
        int v = di.size();
        c[di[0] - '0'][di[v-1] - '0']++;
    }

    lint res = 0;

    rep(i, 10) {
        rep(j, 10) {
            res += c[i][j] * c[j][i];
        }
    }
    cout << res << endl;
    return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007;

int n,dis[_],rdis[_],len;
lint s[_]={0},sr[_]={0};

inline lint sum(lint f[],int l,int r){return f[r]-f[l-1];}

inline lint finder()
{
	lint ans=0;
	for(int i=1;i<=n;i++)
	{
		int rx=(n-i)>>1,x=n-i-rx;
		ans=max(ans,(sum(s,i,i+x-1)+sum(sr,n-rx+1,n))*2+(((n-i)&1)?rdis[n-rx]:dis[n-x]));
	}
	return ans;
}

int main()
{
	len=ty(),n=ty();
	for(int i=1;i<=n;i++)dis[i]=ty(),rdis[i]=len-dis[i],s[i]=s[i-1]+dis[i],sr[i]=sr[i-1]+rdis[i];
	lint ans=finder();
	for(int i=1;i<=n;i++)dis[i]=len-dis[i];
	reverse(dis+1,dis+n+1);
	for(int i=1;i<=n;i++)rdis[i]=len-dis[i],s[i]=s[i-1]+dis[i],sr[i]=sr[i-1]+rdis[i];
	ans=max(ans,finder());
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4992
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
int n,m,c,b[10000];
int main()
{
scanf("%d%d%d",&n,&m,&c);
for(int i=1;i<=m;i++)
    scanf("%d",&b[i]);
int ans=0;
for (int i=1;i<=n;i++)
{
    int sum=0;
    for (int j=1;j<=m;j++)
    {
        int x;
        scanf("%d",&x);
        sum+=b[j]*x;
    }
    sum+=c;
    if (sum>0) ans++;
}
printf("%d\n",ans);
    return(0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final long MOD = 1_000_000_007;

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long n = scanner.nextInt();
        final long m = scanner.nextInt();

        if (Math.abs(n - m) > 1) {
            System.out.println(0);
            return;
        }

        final long nFactorial = factorial(n);
        final long mFactorial = factorial(m);
        if (n == m) {
            System.out.println(nFactorial * mFactorial * 2 % MOD);
        } else {
            System.out.println(nFactorial * mFactorial % MOD);
        }
    }

    private static long factorial(final long a) {
        long retVal = 1;
        for (long i = 2; i <= a; i++) {
            retVal *= i;
            retVal %= MOD;
        }
        return retVal;
    }
}


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

int main() {
  string s; cin>>s;
  ll r=s.size()-1, wc=0, ans=0;
  rep(i,s.size()) if (s[i] =='W') wc++;
  rep(l,wc) {
    if (s[l] == 'B') {
      while(1) {
        if (s[r] == 'W') {
          ans += r-l;
          r--;
          break;
        }
        r--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,sum=0,count=0,login=0;
    cin>>a>>b>>c;
    while (sum<c) {
        login++;
        count++;
        sum+=a;
        if (count==7) {
            sum+=b;
            count=0;
        }
    }
    cout<<login<<endl;
}


Measured memory_bytes: 3124
<?php
fscanf(STDIN, "%d %d", $N, $K);
$arr = explode(' ',rtrim(fgets(STDIN)));
sort($arr);
// var_dump($arr);
$res = 0;
for($i=0;$i<$K;$i++){
    $res += (int)$arr[$i];
}
echo $res;
?>

Measured memory_bytes: 16284
int main(void){
  
  int n,a[100000],m=0,t=0,i;
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++)
    scanf("%d",&a[i]);
  
  for(i=n-1; i>0; i--){
    if(a[i] <= a[i-1])
      t ++;
    if(a[i] > a[i-1]){
      if(m < t)
        m = t;
      t = 0;
    }
  }
  
  printf("%d",m==0 ? t:m);
}  
    

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

int main(){
    ii(a); ii(b); ii(c); ii(d); out(min(a,b)+min(c,d));
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int P;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll inv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = inv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}

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

    cin >> P;

    init(P - 1);

    vector<ll> b(P);
    for (int i = 0; i < P; i++) {
        int a;
        cin >> a;

        if (a) {
            b[0] += 1;
            int s = 1;
            for (int j = 0; j < P; j++) {
                b[P - 1 - j] -= comb(P - 1, j) * s;
                s *= -i;
                s %= P;
            }
        }
    }

    for (int j = 0; j < P; j++) {
        ll t = b[j] % P;
        if (t < 0) t += P;
        cout << t << " \n"[j == P - 1];
    }

    return 0;
}

Measured memory_bytes: 384
s,y=(input() for i in range(2))
ans="{"*len(s);pa=ans
for i in range(len(s)-len(y)+1):
  for j in range(len(y)):
    if s[i+j]!='?' and s[i+j]!=y[j]:break
  else:ans=min(ans,s[:i].replace("?","a")+y+s[i+len(y):].replace("?","a"))
if pa==ans:print("UNRESTORABLE")
  
else:print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<deque>
#include<algorithm>

#include<array>
#include<cmath>
#include<map>

using namespace std;

// const int T=5;

// array<int,T> a;
// map<array<int,T>,array<int,T> > m;

// double pow(array<int,T> a){
//   double d=a[T-1];
//   for(int x=T-2;x>=0;x--){
//     d=(a[x]==0&&d==0)?1:pow(a[x],d);
//   }
//   return d;
// }

// void dfs(int d){
//   if(d<T){
//     for(int i=0;i<T;i++){
//       a[d]=i;
//       dfs(d+1);
//     }
//   }else{
//     auto c=a;
//     sort(begin(c),end(c));
//     if(m.count(c)==0||pow(m[c])<pow(a)-.5){
//       m[c]=a;
//     }
//   }
// }

// int main(){
//   dfs(0);
//   for(auto e:m){
//     for(auto f:e.second){
//       cout<<f<<' ';
//     }
//     cout<<pow(e.second)<<endl;
//   }
// }
  
int main(){
  int N;
  cin>>N;
  deque<int> deq(N);
  for(int i=0;i<N;i++){
    cin>>deq[i];
  }
  sort(begin(deq),end(deq));
  deque<int> ans;

  if(deq[0]<=1){
    int no=count(begin(deq),end(deq),1);
    auto p=upper_bound(begin(deq),end(deq),1);
    auto o=lower_bound(begin(deq),end(deq),1);
    if(o!=end(deq)&&(o-begin(deq))%2){
      swap(*o,o[-1]);
      if(o==p){
	p++;
      }
    }
    ans.insert(begin(ans),begin(deq),p);
    deq.erase(begin(deq),p);
  }
  if(deq.size()>=2&&deq.back()==3&&deq[deq.size()-2]==2){
    swap(deq[deq.size()-2],deq[deq.size()-1]);
  }
  ans.insert(begin(ans),begin(deq),end(deq));
  for(auto e:ans){
    cout<<e<<endl;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
const int N = 200001;

int table[N]; //contains number of 'AC' in the substring upto and including the index i

int main()
{
	int n, q;
	string s;
	cin >> n >> q;
	cin >> s;
	
	table[1] = 0;
	for (int i = 2; i <= n; i++){
		if (s[i - 2] == 'A' && s[i - 1] == 'C'){
			table[i] = table[i - 1] + 1;
		} else {
			table[i] = table[i - 1];
		}
	}
	
	int l, r;
	while(q--){
		cin >> l >> r;
		cout << table[r] - table[l] << endl;
	}
	return 0;
}


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

#define M 998244353

int main(){
   int n, s;
   cin>>n>>s;
   vector<int> a(n);
   rep(i, n) cin>>a[i];

   vector<int> dp(s+1), ndp(s+1);
   int ans=0;
   rep(i, n){
      dp[0]+=1;
      rep(j, s+1){
         ndp[j]=(ndp[j]+dp[j])%M;
         int jj=j+a[i];
         if(jj<=s) ndp[jj]=(ndp[jj]+dp[j])%M;
      }
      ans=(ans+ndp[s])%M;
      swap(dp, ndp);
      ndp=vector<int>(s+1);
   }

   cout<<ans<<endl;

   return 0;                                                                                            }


Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc120/tasks/abc120_b
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){ll n,a,b;
    
    ll ans=100000;
    cin >> n;

    for(ll i=1; i*i<=n; i++){
        if(n%i == 0){
            ll cnt_A=0,cnt_B=0;
            a = n/i;
            b = i;
            while(a>0){
                a /= 10;
                cnt_A++;
            }
            while(b>0){
                b /= 10;
                cnt_B++;
            }
            
            ll f = max(cnt_A,cnt_B);
            if(ans>f) ans=f;
            
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())

P = int(N//100)
Q = N%100

flag = 0

while N > 0:
  P = int(N//100)
  Q = N%100
  
  if(Q <= P*5):
    print(1)
    flag  = 1
    break
  else:
    N -= 2100

if(flag == 0):
  print(0)

Measured memory_bytes: 3060