akhauriyash/Code-Regression huggingface dataset:
def main(N, lst):
    lst.append(10**9 + 1)
    ret = 0
    val = 0
    tmp = lst[0]
    for x in lst[1::]:
        if tmp >= x:
            val += 1
        else:
            ret = max(val, ret)
            val = 0
        tmp = x

    return ret


if __name__ == "__main__":
    N = int(input())
    lst_H = list(map(int, input().split()))
    print(main(N, lst_H))


Measured memory_bytes: 14224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const int maxn=2e5+10;
int n,a[maxn],f[62][maxn];
long long k;
int main()
{
	scanf("%d%lld",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),f[0][i]=a[i];
	for (int j=1;j<=61;j++)
	 for (int i=1;i<=n;i++) f[j][i]=f[j-1][f[j-1][i]];
	int lc=1;
	for (int i=61;i>=0;i--) if ((k>>i)&1) lc=f[i][lc];
	printf("%d\n",lc);
return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N); cin >> A;
        bool ok = true;
        rep(i, N) if(A[i] % 2 == 0) ok &= A[i] % 3 == 0 or A[i] % 5 == 0;
        cout << (ok ? "APPROVED" : "DENIED") << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_HW = 1005;
const ll MOD = 1e9+7;
char grid[MAX_HW][MAX_HW];
ll dp[MAX_HW][MAX_HW];

int main()
{
	int H,W;
	cin >> H >> W;
	rep(i,H)
	{
		rep(j,W)
		{
			cin >> grid[i][j];
		}
	}

	dp[0][0] = 1;
	rep(i,H-1)
	{
		if (grid[i+1][0] == '.' && dp[i][0] == 1) dp[i+1][0] = 1;
	}
	rep(j,W-1)
	{
		if (grid[0][j+1] == '.' && dp[0][j] == 1) dp[0][j+1] = 1;
	}
	rep(i,H-1)
	{
		rep(j,W-1)
		{
			if (grid[i+1][j+1] == '.')
			{
				dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j]) % MOD;
			}
		}
	}
	/*
	rep(i,H)
	{
		rep(j,W)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << dp[H-1][W-1] << endl;
	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
struct Node{
    int right,left,parent;
    Node(){ right=-1;left=-1;parent=-1; }
};
int main(){
    int n;
    scanf("%d",&n);
    Node tree[n];
    int id,k,c;
    for(int i=0;i<n;++i){
        scanf("%d%d",&id,&k);
        if(k){ scanf("%d",&c); tree[id].left=c; tree[c].parent=id; }
        for(int j=1;j<k;++j){
            id=c;
            scanf("%d",&c);
            while(~tree[id].right) id=tree[id].right;
            tree[id].right=c;
            tree[c].parent=tree[id].parent;
        }
    }
    for(int i=0;i<n;++i){
        int depth=0;
        int pare=tree[i].parent;
        while(pare!=-1){
            depth++;
            pare=tree[pare].parent;
        }
        printf("node %d: parent = %d, depth = %d, %s, [",i,tree[i].parent,depth,tree[i].parent==-1?"root":tree[i].left!=-1?"internal node":"leaf");
        int child=tree[i].left;
        if(~child){
            printf("%d",child);
            while(tree[child].right!=-1){
                printf(", %d",tree[child].right);
                child=tree[child].right;
            }
        }
        printf("]\n");
    }
    return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b;
    cin>>a>>b;
    cout<<max(a+b, max(a-b,a*b))<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  int N=IN(),total=0,ope=0;char stones[N+1];if(!scanf("%s",stones))return-1;
  rep(i,N){if(stones[i]=='R')total++;} 
  ope=total;rep(i,total){if(stones[i]=='R')ope--;}
  return printf("%d\n",ope),0;
}

Measured memory_bytes: 1928
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(;;){
                int m,f,r;
                scanf("%d %d %d",&m,&f,&r);
                if(m+f+r==-3) break;
                if(m==-1 || f==-1) printf("F\n");
                else if(m+f>=80) printf("A\n");
                else if(m+f>=65) printf("B\n");
                else if(m+f<30) printf("F\n");
                else if(m+f>=50 || r>=50) printf("C\n");
                else if(m+f>=30) printf("D\n");
        }
        return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int comp(const void* a, const void *b) {
	return *(int*)a - *(int*)b;
}

int main(){
    int X, N, p[102], num;
    bool flag = 1;

    cin >> X >> N;
    for(int i = 0; i < N; i ++){
        cin >> p[i];
    }
    qsort(p, N, sizeof(int), comp);
    for(int j = 0; j < N; j ++){
        if(X == p[j]){
            flag = 0;
            num = j;
        }
    }
    if(flag){
        cout << X << endl;
        return 0;
    }
    for(int k = 1; k <= (N + 1) / 2; k ++){
        if(p[max(num - k, 0)] != (p[num] - k)){
            cout << p[num] - k << endl;
            break;
        }
        if(p[min(num + k, N - 1)] != (p[num] + k)){
            cout << p[num] + k << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#include <map>
#define ll long long 
#define PI 3.14159265358979323846
#define INF 10000000000
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll D, T, S;
	cin >> D >> T >> S;
	ll ans = T * S;
	if (ans >= D) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>

using namespace std;

void Tile1(vector<string>&, int, int, int, int);
void Tile2(vector<string>&, int, int, int, int);

int main(){
  int i, j, w, h, isFound, count;
  string str;
  vector<string> data;

  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    for(i=0; i<h; ++i){
      cin >> str;
      data.push_back(str);
    }

    for(i=0, isFound=0; i<h; ++i){
      for(j=0; j<w; ++j){
        if(data[i][j] == '@'){
	  isFound = 1;
	  break;
	}
      }
      if(isFound == 1) break;
    }

    Tile1(data, i, j, w, h);

    for(i=0, count=0; i<h; ++i){
      for(j=0; j<w; ++j){
        if(data[i][j] == '@') ++count;
      }
    }

    cout << count << endl;
    data.clear();
  }

  return 0;
}

void Tile1(vector<string>& data, int i, int j, int w, int h){
  data[i][j] = '@';
  Tile2(data, i-1, j, w, h);
  Tile2(data, i, j-1, w, h);
  Tile2(data, i+1, j, w, h);
  Tile2(data, i, j+1, w, h);
}

void Tile2(vector<string>& data, int i, int j, int w, int h){
  if(i>-1 && i<h && j>-1 && j<w && data[i][j]=='.')
    Tile1(data, i, j, w, h);
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

void solve(void){

  long long int A,B,C;
  cin >> A >> B >> C;
  
  int count =0;
	if(A==B&&C!=B) count++;
  if(A==C&&B!=A) count++;
  if(B==C&&A!=B) count++;
  
  if(count==1){
  cout << "Yes" <<endl;
  }else{
  cout << "No" <<endl;
  }
  
return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int AINT[800005];
int dp[200005];
void build(int nod,int st,int dr)
{
    if(st==dr)
    {
        AINT[nod]=dp[st];
        return ;
    }
    int mid=(st+dr)/2;
    build(nod*2,st,mid);
    build(nod*2+1,mid+1,dr);
    AINT[nod]=min(AINT[2*nod],AINT[2*nod+1]);
}
void u(int nod,int st,int dr,int pos,int val)
{
    if(dr<pos||st>pos)return ;
    if(st==dr){AINT[nod]=val;return ;}
    int mid=(st+dr)/2;
    u(nod*2,st,mid,pos,val);
    u(nod*2+1,mid+1,dr,pos,val);
    AINT[nod]=min(AINT[2*nod],AINT[2*nod+1]);
}
int q(int nod,int st,int dr,int S,int D)
{
    if(dr<S||st>D)return 1<<30;
    if(S<=st&&dr<=D)return AINT[nod];
    int mid=(st+dr)/2;
    return min(q(nod*2,st,mid,S,D),q(nod*2+1,mid+1,dr,S,D));
}
int N,Q;
vector<int> V[200005];
int B[200005],rez;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
        {cin>>B[i];rez+=!B[i];}
    cin>>Q;
    for(int i=1;i<=Q;i++)
    {
        int x,y;
        cin>>x>>y;
        V[x].push_back(y);
    }
    for(int i=2;i<=N+1;i++)dp[i]=1<<30;
    build(1,1,N+1);
    for(int i=1;i<=N;i++)
    {
        vector<int> updates;
        for(auto it:V[i])
        {
            dp[it+1]=min(dp[it+1],q(1,1,N+1,i,it+1));
            updates.push_back(it+1);
        }
        dp[i+1]=min(dp[i+1],dp[i]+(B[i] ? 1:-1));
        dp[i]=1<<30;
        updates.push_back(i);
        updates.push_back(i+1);
        for(auto it:updates)
            u(1,1,N+1,it,dp[it]);
    }
    rez+=dp[N+1];
    cout<<rez;
    return 0;
}

Measured memory_bytes: 14080
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> b(n - 1);
    for(int i = 0; i < n - 1; i++){
        std::cin >> b[i];
    }

    long long sum = b[0] + b[n - 2];
    for(int i = 0; i < n - 2; i++){
        sum += std::min(b[i], b[i + 1]);
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
#define true 39
#define false 0
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	int k;
	char s[101];
	scanf("%d", &k);
	scanf("%s", s);
	if (strlen(s) > k) 
	{
		for (int i = 0; i != k; i++) 
		{
			printf("%c", s[i]);
		}
		printf("...");
	}
	else {
		printf(s);
	}
	return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

struct num{
	long long r,s;
	bool operator <(const num &t) const{
		if (r * t.s == s * t.r) return r < t.r;
		return r * t.s < s * t.r;
	}
};

int main()
{
	vector<num> ls;
	for (int s=1;s<=140;s++){
		for (int u=1;u<=9;u++){
			if (s - u < 0) break;

			int t = s - u;
			long long r = 0;
			for (long long p=1;t;p*=10){
				if (t >= 9) r += 9 * p, t -= 9;
				else r += t * p, t = 0;
			}

			int l = (s-u+8)/9;
			long long base = 1;
			for (int k=0;k<l;k++) base *= 10;
			while (base < 1e16){
				ls.push_back({ r + base*u,s });
				base *= 10;
			}
		}
	}
	sort(ls.begin(),ls.end());

	long long last = 0;
	int K; scanf ("%d",&K);
	for (int i=0;i<ls.size();i++){
		if (last < ls[i].r){
			last = ls[i].r;
			if (K > 0){
				printf ("%lld\n",last);
				K--;
			}
		}
	}

	return 0;
}


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

int H, W, A, B;
int C1[1009], C2[1009], T[1009][1009];

void solve() {
	for (int i = H - 1; i >= 0; i--) {
		vector<pair<int, int>> J;
		for (int j = 0; j < W; j++) J.push_back(make_pair(C2[j], j));
		sort(J.begin(), J.end());
		reverse(J.begin(), J.end());

		for (int j = 0; j < C1[i]; j++) {
			T[i][J[j].second] = 1;
			C2[J[j].second]--;
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) printf("%d", T[i][j]);
		printf("\n");
	}
}

int main() {
	cin >> H >> W >> A >> B;
	for (int i = 0; i <= H; i++) {
		for (int j = 0; j <= W; j++) {
			int s1 = i * A + (H - i) * (W - A);
			int s2 = j * B + (W - j) * (H - B);

			if (s1 == s2) {
				for (int k = 0; k < i; k++) C1[k] = A;
				for (int k = 0; k < j; k++) C2[k] = B;
				for (int k = i; k < H; k++) C1[k] = (W - A);
				for (int k = j; k < W; k++) C2[k] = (H - B);
				solve();
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>

using namespace std;

int main(void)
{
    int a, b;

    cin >> a >> b;

    if(a%3==0 || b%3==0 || (a+b)%3==0){
        cout << "Possible" << endl;
    }

    else{
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int[] T = new int[N];
        for (int i = 0; i < N; ++i) {
            T[i] = sc.nextInt();
        }
        Arrays.sort(T);

        int min = 0;
        int start = K;
        int busCnt = 0;
        int pCnt = 0;
        for (int i = 0; i < N; ++i) {
            if (i == 0) {
                min = T[i];
                start = T[i] + K;
                ++pCnt;
                ++busCnt;
            } else {
                if (T[i] > start) {
                    min = T[i];
                    start = T[i] + K;
                    pCnt = 1;
                    ++busCnt;
                } else if (pCnt >= C) {
                    min = T[i];
                    start = T[i] + K;
                    pCnt = 1;
                    ++busCnt;
                } else {
                    min = T[i];
                    ++pCnt;
                }
            }
        }
        _out.println(busCnt);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 52284
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define MP make_pair
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STRING(x) string x;cin>>x;
# define STR(x) STRING(x);
# define DOUBLE(x) double x;cin>>x;
# define DBL(x) DOUBLE(x); 
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl
# define INIT(a) memset(a,-1,sizeof a)
# define CLR(a) memset(a,0,sizeof a)
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
//const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const int M = 1000000007;
template<class T> void debug(T a) { for ( auto i : a )cout << i << endl; }

string x, y;
int memo[1100][1100];
int dp(int l, int r)
{
	if ( memo[l][r] != -1 )return memo[l][r];
	if ( l == x.size() && r == y.size() )return 0;
	int ans = 0;
	if ( x[l] == y[r] )
		ans = max(ans, dp(l + 1, r + 1) + 1);
	if ( l != x.size() )
		ans = max(ans, dp(l + 1, r));
	if ( r != y.size() )
		ans = max(ans, dp(l, r + 1));
	return memo[l][r] = ans;
}
int main()
{
	INT(n);
	while ( n-- )
	{
		cin >> x >> y;
		INIT(memo);
		cout << dp(0, 0) << endl;
	}
}

Measured memory_bytes: 8032
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int N,M;
   cin>>N>>M;
   vector<int>AC(N);
   vector<int>WA(N);
   int sumA=0;int sumW=0;
   for(int i=0;i<M;i++){
       int p;
       string S;
       cin>>p>>S;
       p--;
       if(AC[p]){continue;}
       if(S=="AC"){AC[p]++;sumA+=AC[p];sumW+=WA[p];}
       if(S=="WA"){WA[p]++;}
   }
   cout<<sumA<<" "<<sumW<<endl;
return 0;}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	string s, t;
  	string ans="No";
	cin >> s >> t;
	ll x = stoi(s + t);
	for (ll i = 1; i <= 1000; i++) {
		if (i*i == x) {
			ans="Yes";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        int K, S;
        {int[] a = r.ii(); K = a[0]; S = a[1];}
        int count = 0;
        for(int i = 0; i < K+1; i++)
            for(int j = 0, k; j < K+1; j++)
                if(0 <= (k =  S-i-j) && k <= K)
                    count++;
        println(count);                    
    }
    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef complex<int> P;
int f,p;
string s;
bool x(P p){
  if(abs(p.real())>10000||abs(p.imag())>10000)return 1;
  return 0;
}
P gacho();
P get_gacho(){
  if(s[p]=='('){
    p++;
    P r=gacho();
    p++;
    return r;
  }
  if(s[p]=='i'){
    p++;
    return P(0,1);
  }
  int num=0;
  while(isdigit(s[p])){
    num*=10,num+=(s[p]-'0');
    p++;
    if(x(P(num,0)))f++;
  }
  return P(num,0);
}
P gacho2(){
  P res=get_gacho();
  while(p<s.size()){
    if(s[p]=='*'){
      p++;
      P r=get_gacho();
      res*=r;
      if(x(res))f++;
    }
    else break;
  }
  return res;
}
P gacho(){
  P res=gacho2();
  while(p<s.size()){
    if(s[p]=='+'){
      p++;
      P r=gacho2();
      res+=r;
      if(x(res))f++;
    }
    else if(s[p]=='-'){
      p++;
      P r=gacho2();
      res-=r;
      if(x(res))f++;
    }
    else break;
  }
  return res;
}
int main(){
  while(cin>>s){
    p=f=0;
    P ans=gacho();
    int a=ans.real(),b=ans.imag();
    if(f)cout<<"overflow"<<endl;
    else{
      if(!a&&!b)cout<<0<<endl;
      if(!a&&b)cout<<b<<'i'<<endl;
      if(a&&!b)cout<<a<<endl;
      if(a&&b){
        cout<<a;
        if(b>0)cout<<'+';
        cout<<b<<'i'<<endl;
      }
    }
  }
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    int ans = INT_MAX;
    for (int a = 1; N - a >= a; a++) {
        int b = N - a;

        int tot = 0;
        for (int tmp = a; tmp; tmp /= 10)
            tot += tmp % 10;
        for (int tmp = b; tmp; tmp /= 10)
            tot += tmp % 10;
        ans = min(ans, tot);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
using namespace std;

const int mod=1e9+7;

signed main(){
    int n;
    cin >> n;
    vi w(n);
    int sum = 0;
    rep(i,n)
    {
        cin >> w[i];
        sum+=w[i];
        w[i]=sum;
    }

    vi ans(n);
    rep(i,n)
    {
        ans[i]=abs(sum-w[i]*2);
    }
    sort(all(ans));

    cout << ans[0] << endl;
}



Measured memory_bytes: 256
n=int(input())
mi=n
for k in range(n+1):
    six=0
    nine=0
    k2=n-k
    while k>0:
        six+=k%6
        k//=6
    while k2>0:
        nine+=k2%9
        k2//=9
    mi=min(mi,six+nine)
print(mi)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
struct graph{
    vi v;
};
graph G[MAX_];
int n,m;
int s,t;

void bfs(){
    int arr[n+1][3];  // vertices , shortest distance modulo
    int nax = 1e8;
    for(int i =0;i<=n;i++){
        arr[i][0] = arr[i][1] = arr[i][2]= nax;
    }
    arr[s][0] = 0;
    queue<pair<int,int> > q;
    q.push({s,0});  // s to t.
    while(!q.empty()){
        pair<int,int> temp = q.front();
        q.pop();
        int from = temp.ff;
        int mo = temp.ss;
        for(int i =0;i<G[from].v.size();i++){
            int to = G[from].v[i];
            int distance = (mo+1)%3;
            if(arr[to][distance]==nax){
                arr[to][distance] = arr[from][mo] + 1;
                q.push({to,distance});
            }
        }
    }
    if(arr[t][0] == nax){
        cout << -1 << "\n";
    }
    else{
        int ans = arr[t][0];
        cout << ans/3 ;
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    f(m){
        int x,y;  
        cin>>x>>y;
        G[x].v.pb(y); //directed graph
    }
    cin>>s>>t;
    bfs();
    return 0;
}
    


Measured memory_bytes: 9216
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] num = new int[n];
		for(int i = 0;i < n;i++){
			num[i] = saori.saori_hayami();
		}
		Arrays.sort(num);
		System.out.println(num[num.length-1] - num[0]);

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
using namespace std;
int main() {
	int H, W, i;
	string row, output;
	while (true) {
		row = "";
		output = "";
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (i = 0; i < W; i++) row += '#';
		row += '\n';
		for (i = 0; i < H; i++)output += row;
		cout << output << endl;
	}
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string s;
int main(){
	ios::sync_with_stdio(0);
	cin>>s;
	int ans=0,now=0;
	rep(i,3){
		if(s[i]=='R')
		now++;
		if(s[i]=='S'){
			ans=max(ans,now);
			now=0;
		}
	}
	ans=max(ans,now);
	cout<<ans;
	re 0;
}

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

int main(){
  int n;
  cin >>n;
  for(int a=1; a<10; a++)for(int b=1; b<10; b++){
     if(a*b==n){
       cout <<"Yes"<<endl;
       
       return 0;
     }
  }
  cout <<"No" <<endl;
}  

Measured memory_bytes: 256
import sys
from collections import Counter


if __name__ == '__main__':
    # ??????????????\???
    # data = [5, 6, 3, 5, 8, 7, 5, 3, 9, 7, 3, 4]
    data = []
    for line in sys.stdin:
        data.append(int(line.strip()))
    # print(data)

    # ?????????????¢????
    c = Counter(data)
    max_freq = c.most_common(1)[0][1]  # ???????????????????????°????¨???¶
    modes = []
    for val, freq in c.most_common():
        if freq != max_freq:
            break
        modes.append(val)

    # ???????????¨???
    modes.sort()
    for i in modes:
        print(i)

Measured memory_bytes: 7952
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)cout<<c;
    else if(b==c)cout<<a;
    else cout<<b;
    
	return 0;
}


Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) <= (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;


void solve(){
    string s, t;
    cin >> s >> t;
    vector<vector<int>> grid(s.size()+1, vector<int>(t.size()+1));

    grid[0][0] = 0;
    FOR(i,1,s.size()){
        grid[i][0] = 0;
    }
    FOR(i,1,t.size()){
        grid[0][i] = 0;
    }

    FOR(i,1,s.size()){
        FOR(j,1,t.size()){
            if(s[i-1]==t[j-1]){
                grid[i][j] = grid[i - 1][j - 1] + 1;
            }else{
                grid[i][j] = max(grid[i][j - 1], grid[i - 1][j]);
            }
        }

    }
    cout << grid[s.size()][t.size()] << endl;

}



int main(){

    int n;
    cin >> n;
    REP(i,n){
        solve();
    }

    return 0;
}



Measured memory_bytes: 6864
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    // 0: remain: 0
    let mut dp: Vec<[usize; 13]> = vec![[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
    let mut mul = 1;
    for (i, c) in s.chars().rev().enumerate() {
        let arr = [0; 13];
        dp.push(arr);
        if c == '?' {
            for n in 0..10 {
                let remain = (n * mul) % 13;
                for (j, v) in dp[i].clone().iter().enumerate() {
                    dp[i + 1][(j + remain) % 13] += *v;
                    dp[i + 1][(j + remain) % 13] %= 10_usize.pow(9) + 7;
                }
            }
        } else {
            let n = c.to_digit(10).unwrap() as usize;
            let remain = (n * mul) % 13;
            for (j, v) in dp[i].clone().iter().enumerate() {
                dp[i + 1][(j + remain) % 13] += *v;
                dp[i + 1][(j + remain) % 13] %= 10_usize.pow(9) + 7;
            }
        }
        mul *= 10;
        mul %= 13;
    }
    println!("{}", dp[dp.len() - 1][5]);
}


Measured memory_bytes: 20064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n;
  cin>>h>>w>>n;
  int a=max(h,w);
  if(n>=a){
  int k=n/a;
  if(n%a!=0)k++;
  cout<<k<<endl;
  }else cout<<1<<endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int p[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97},c[25];

int main(void){
	int n,ans=0,i,j,k,x;
	cin >> n;
	for(i=0; i<25; ++i){
		x = n;
		while(x){
			x /= p[i];
			c[i] += x;
		}
	}
	for(i=0; i<25; ++i){
		if(c[i]>73){
			++ans;
		}
	}
	for(i=0; i<25; ++i){
		for(j=0; j<25; ++j){
			if(i==j){continue;}
			if(c[i]>1 && c[j]>23){
				++ans;
			}
			if(c[i]>3 && c[j]>13){
				++ans;
			}
		}
	}
	for(i=0; i<25; ++i){
		for(j=i+1; j<25; ++j){
			for(k=0; k<25; ++k){
				if(i==k || j==k){continue;}
				if(c[i]>3 && c[j]>3 && c[k]>1){
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<functional>

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

using namespace std;

int toMinute(int t){ return (t/100*60)+(t%100); }

enum{BEGIN,END};
struct Info{
	int t,type;
	Info(int T,int TYPE):t(T),type(TYPE){}
	bool operator>(const Info &info)const{
		if(t==info.t)	return type>info.type;
		return t>info.t;
	}
};

int main(){
	for(int n,s,g;scanf("%d%d%d",&n,&s,&g),n||s||g;){
		s=toMinute(s);
		g=toMinute(g);
		priority_queue< Info,vector<Info>,greater<Info> > pq;
		rep(i,n){
			int k;	scanf("%d",&k);
			pq.push(Info(s,BEGIN));
			rep(j,k){
				int a,b;	scanf("%d%d",&a,&b);
				a=toMinute(a);	pq.push(Info(a,END));
				b=toMinute(b);	pq.push(Info(b,BEGIN));
			}
			pq.push(Info(g,END));
		}

		int ans=0,dup=0,bef=s;
		while(!pq.empty()){
			Info a=pq.top();	pq.pop();
			if(a.type==BEGIN){
				if(dup==0)	bef=a.t;
				dup++;
			}
			else{
				dup--;
				if(dup==0)	ans=max(ans,a.t-bef);
			}
		}

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

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int n_max=100005;
int dp[n_max];

 
int main() {

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n)    cin >> h[i];

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    rep(i,n-2) {
        dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i+2]-h[i]));
    }
    
    cout << dp[n-1] << endl;

 return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
  long long H,W;
  cin>>H>>W;
  long long answer=99999999999;
  for(long long i=1;i<H;i++){
    long long A=i*W;
    long long B,C;
    if((H-i)%2==0||W%2==0){
      B=((H-i)*W)/2;
      C=B;
    }
    else{
      if(H-i<W){
        B=(H-i)*(W/2);
      }
      else{
        B=((H-i)/2)*W;
      }
      C=(H-i)*W-B;
    }
    answer=min(answer,max(A,max(B,C))-min(A,min(B,C)));
  }
  for(long long i=1;i<W;i++){
    long long A=i*H;
    long long B,C;
    if((W-i)%2==0||H%2==0){
      B=((W-i)*H)/2;
      C=B;
    }
    else{
      if(W-i<H){
        B=(W-i)*(H/2);
      }
      else{
        B=((W-i)/2)*H;
      }
      C=(W-i)*H-B;
    }
    answer=min(answer,max(A,max(B,C))-min(A,min(B,C)));
  }
  cout<<answer<<endl;
  
  return 0;
}

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

using ll=long long; 



void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	bool mod[110];
	memset(mod,0,sizeof mod);
	for(int i=a; ;i+=a){
		if(mod[i%b]){
			cout<<"NO"<<endl;
			return;
		}
		if(i%b==c){
			cout<<"YES"<<endl;
			return;
		}
		mod[i%b]=1;
	}
}

signed main(){
	//while(1)
	solve();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin>>n>>m>>k;
	bool ok=false;
	REP(i, n+1){
		REP(j, m+1){
			if(i*(m-j)+j*(n-i)==k){
				ok=true;
				i=n+1;
				j=m+1;
			}
		}
	}
	cout<<(ok ? "Yes" : "No")<<'\n';
	return 0;
}


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

int main()
{
    int N, M;
    std::cin >> N >> M;

    std::vector<int> L, R;
    for (int i = 0; i < M; i++)
    {
        int l_row, r_row;
        std::cin >> l_row >> r_row;

        L.push_back(l_row);
        R.push_back(r_row);
    }

    // LとRの共通範囲を求める
    int minID = 1;
    int maxID = N;
    for (int i = 0; i < M; i++)
    {
        if (L[i] > minID)
        {
            minID = L[i];
        }

        if (R[i] < maxID)
        {
            maxID = R[i];
        }
    }

    if (minID <= maxID)
    {
        std::cout << maxID - minID + 1 << std::endl;
    }
    else
    {
        std::cout << 0 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<queue>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
int N,M;
ll a[maxn];

int main()
{
	ios;
	cin>>N>>M;
	for(int i=0;i<N;i++) cin>>a[i];
	ll ans=a[0];
	for(int i=1;i<N;i++) 
		ans=ans*a[i]/__gcd(ans,a[i]);
	for(int i=0;i<N;i++)
	{
		if((ans/a[i])%2==0)
		{
			cout<<0;
			return 0;		
		}
	}
	cout<<((M*2/ans+1)/2);
	return 0;	
}

Measured memory_bytes: 4404
#include <stdio.h>
#include <stdlib.h>
#define N_MAX 1000

typedef struct node { int n; struct node* next; } *node;

node newNode(int n){
     node a=malloc(sizeof(struct node));
     a->n = n;
     return a;
}

int main(int argc, char *argv[]){
     node joseph, t; int i, n, m;

     while(scanf("%d%d",&n,&m), n!=0){
	  /* struct a link list */
	  t = joseph = newNode(1);
	  for(i=2; i<=n; i++) joseph = joseph->next = newNode(i);
	  joseph->next = t;

	  /* potato */
	  while(joseph->next != joseph){
	       for(i=0; i<m-1; i++) joseph = joseph->next;
	       t = joseph->next;
	       joseph->next = t->next;
	       free(t);
	  }

	  printf("%d\n",joseph->n);
	  free(joseph);
     }

     return 0;
}

Measured memory_bytes: 0
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i;
    double r, t, x, y;

    for(;;){
      n = sc.nextInt();
      if(n == -1)break;

      r = Math.sqrt(n);
      t = 0;
      for(i = 0;i < n - 1;i++)t += Math.atan(1.0 / Math.sqrt(i + 1));
      x = r * Math.cos(t);
      y = r * Math.sin(t);
      out.printf("%f%n%f%n", x, y);
    }


    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17224
from collections import Counter
MOD = 998244353
N = int(input())
D = list(map(int,input().split(' ')))

if D[0] != 0:
    print(0)
    exit()

d = Counter(D)

if d[0] != 1:
    print(0)
    exit()

Ns = 1
ans = 1
for i in range(1,N):
    if i not in d:
        print(0)
        exit()
    ans = (ans * d[i-1] ** d[i]) % MOD
    Ns += d[i]
    if Ns == N:
        break
print(ans)






Measured memory_bytes: 19936
L,R = map(int, input().split())
 
if R-L>=2019:
    print(0)
    exit()
    
min = 2020 * 2020
for i in range(L,R+1):
    for j in range(i+1,R+1):
        if min > i * j % 2019:
            min = i * j % 2019
 
print(min)

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << max(a*b, c*d) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <utility>
 
using namespace std;
 
int INF = 1 << 28;
int n;
int m;
char map[100][100];
int visited[100][100];
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
int ans;
 
void solve(pair<int,int> pos, int c) {
 
    int x = pos.first;
    int y = pos.second;
    
    if (visited[y][x] <= c)
        return;
    visited[y][x] = c;
    if (ans <= c) {
        return;
    }
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
		if (nx < 0 || ny < 0 || nx >= n || ny >= m) {
        ans = c;
        return;
    }
            solve(make_pair(nx, ny), c + ((map[y][x] != '#' && map[ny][nx] == '#') ? 1 : 0));
    }
}
 
int main(){
    while (1) {
        ans = INF;
        cin>>n;
        cin>>m;
        if ((n | m) == 0)
            break;
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                cin >> map[i][j];
                visited[i][j] = INF;
            }
        }
        int sx = 0;
        int sy = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (map[i][j] == '&') {
                    sx = j;
                    sy = i;
                    i = INF;
                    break;
                }
            }
        }
        solve(make_pair(sx,sy), 0);
 
        cout <<ans<<"\n";
    }
}

Measured memory_bytes: 1504
N, K = map(int, input().split())

P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))

best = max(C)
for i in range(N):
    curr = 0
    score = [0]
    start = i
    while P[start] != i:
        start = P[start]
        curr += C[start]
        score.append(curr)
    cycle_score = score[-1] + C[i]
    cycle_len = len(score)

    for j in range(cycle_len):
        if j <= K and j != 0:
            cycles = (K - j)//cycle_len
            thing = score[j] + max(0, cycle_score) * cycles
            best = max(best, thing)
        elif j == 0 and K >= cycle_len:
            thing = cycle_score * K // cycle_len
            best = max(best,thing)

print(best)


Measured memory_bytes: 83784
#include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> train;
	int num;
	while(cin>>num){
		if(num != 0){
			train.push_back(num);
		}else if(num == 0){
			cout<<train[train.size()-1]<<endl;
			train.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int a, b;
    cin >> a >> b;
    char c[100][100];
    rep(i, 50) rep(j, 100) c[i][j] = '#';
    rep(i, 50) rep(j, 100) c[i+50][j] = '.';

    int x = 1, y = 1;
    rep(j, a - 1){
        c[y][x] = '.';
        if (x + 2 < 100) x += 2;
        else y += 2, x = 1;
    }

    x = 1, y = 51;
    rep(j, b - 1){
        c[y][x] = '#';
        if (x + 2 < 100) x += 2;
        else y += 2, x = 1;
    }

    cout << 100 << " " << 100 << endl;
    rep(i, 100) {
        rep(j, 100) cout << c[i][j];
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int,input().split()))
lis.sort()
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if lis[i]+lis[j]>lis[k] and lis[i] != lis[j] and lis[j] != lis[k]:
        ans +=1
print(ans)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,x;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x;
		if(x%2==0&&(x%3&&x%5)){
			cout<<"DENIED"<<endl;
			return 0;
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 101

int n,Go[N],Back[N],Link[N],Keep[N][N],Count=1;

void dfs(int x){

	int i;
	Go[x] = Count++;

	for(i = 0; i < Link[x]; i++){
		if(Go[Keep[x][i+1]] == 0){
			dfs(Keep[x][i+1]);
		}
	}
	Back[x] = Count++;
}
  
int main(){

	int i,j,Num;

	scanf("%d",&n);
	for( i = 0; i < n; i++){
		Go[i+1] = Back[i+1] = 0;
		scanf("%d",&Num);
		scanf("%d",&Link[Num]);
		for(j = 0; j < Link[Num]; j++) scanf("%d",&Keep[Num][j+1]);
	}

	for(i = 0; i < n; i++) if(Go[i+1] == 0) dfs(i+1);

	for(i = 0; i < n; i++){
		printf("%d %d %d\n",i+1,Go[i+1],Back[i+1]);
	}

	return 0;
}


Measured memory_bytes: 2112