akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x;
	set<pll>s;
	for(i=0;i<=4000;i++)
	{
		s.insert(mp(i*i*i*i*i,i));
		s.insert(mp(-i*i*i*i*i,-i));
	}

	vector<pll>v;
	for(auto it:s)
		v.pb(it);


	for(i=0;i<sz(v);i++)
	{
		for(j=0;j<sz(v);j++)
		{
			if(v[j].ff-v[i].ff==x)
			{
				cout<<v[j].ss<<" "<<v[i].ss<<endl;
				return 0;
			}
		}
	}

}

Measured memory_bytes: 4284
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int N;
char S[300005];
int x[10][10];
int y[10][10][10];

int main(void) {
    scanf("%d", &N);
    scanf("%s", S);
    int s = S[0] - '0';
    int t = S[1] - '0';
    x[s][t] = 1;
    rep(i, 2, N) {
      int s = S[i] - '0';
      pair<int, int> pr[1005];
      int p = 0;
      //printf("--%d--\n", s);


      rep(j, 0, 10) {
        rep(k, 0, 10) {
          if (x[j][k] == 1) {
            //printf("%d %d %d\n", j, k, s);

            y[j][k][s] = 1;
            pr[p++] = make_pair(j, s);
            pr[p++] = make_pair(k, s);
          }
        }
      }
      rep(j, 0, p) x[pr[j].first][pr[j].second] = 1;
    }

    rep(i, 0, 10) {
      rep(j, 0, 10) {
        rep(k, 0, 10) {
          if (y[i][j][k] == 1) {
            
            ans++;
          }
        }
      }
    }
   

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

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main() {
int n,ans=0;
  cin >> n;
  for(int i =1;i<=n;i++){
    int a=0;
     for(int j =1;j<=i;j++){
      if(i%j==0&&i%2!=0)
      {
        a+=1;
      }
    }
     if(a==8)ans++;
  }
  cout <<ans;
  }

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n,A,B,C;
vector<int> l(8);
int dfs(int depth,int a,int b,int c){
    if(depth == n){
        if(min(a,min(b,c))>0){
            return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        }else{
            return 1e9;
        }
    }
    int ret0 = dfs(depth+1,a,b,c);
    int ret1 = dfs(depth+1,a+l[depth],b,c) + 10;
    int ret2 = dfs(depth+1,a,b+l[depth],c) + 10;
    int ret3 = dfs(depth+1,a,b,c+l[depth]) + 10;
	return min({ret0,ret1,ret2,ret3});
}
int main(){
    cin >> n >> A >> B >> C;
    rep(i,n) cin >> l[i];
    cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
      string s;

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

  bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
  {

    if(a.s==b.s)
    {
      return a.f<b.f;
    }
    return a.s<b.s;
  }

  bool vis[10000][10000];

  int n;
  int currx=0,curry=0;

  void dfs(int x,int y,bool dir,int idx)
  {

    if(idx==n)
    {
      return;
    }

    currx=x;
    curry=y;

      vis[x][y]=1;
      if(s[idx]=='F')
      {
        if(dir==0)
        {
          currx++;
        }
        else
        {
          curry++;
        }

        dfs(currx,curry,dir,idx+1);
        return;
      }
      else
      {
        dfs(currx,curry,!dir,idx+1);
        dfs(currx,curry,dir,idx+1);
        
          return;
      } 

      return;
  }


  int digsum(int n)
  {
    int ans=0;
    while(n)
    {
      ans+=(n%10);
      n/=10;
    }

    return ans;
  }
  int32_t main()
  {         
    
     
      IOS

        

      int x,y;
      cin>>x>>y;

      int ans=0;
      while(x<=y)
      {
        ans++;
        x*=2;
      }


      cout<<ans;
      return 0;
  }           

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

int main() {
  int s, w;
  cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}

Measured memory_bytes: 3640
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

ll dp[5000][5000];

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    for(int s = 1; s <= n; s++){
        for(int l = 0; l + s <= n; l++){
            int r = l + s;
            if((n - s) % 2 == 0){
                dp[l][r] = max(dp[l + 1][r] + a[l], dp[l][r - 1] + a[r - 1]);
            } else {
                dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1]);
            }
        }
    }

    cout << dp[0][n] << endl;

}

Measured memory_bytes: 118400
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 1
for i in a:
    ans = lcm(ans,i)
for i in a:
    if (ans//i) % 2 == 0:
        print(0)
        exit()
print(((m//(ans//2))+1)//2)

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

using namespace std;

int main() {
  int sx, sy, tx, ty;
  int i;
  
  cin >> sx >> sy >> tx >> ty;
  
  for (i = 0; i < (ty - sy); i++) {
    cout << "U";
  }
  
  for (i = 0; i < (tx - sx); i++) {
    cout << "R";
  }
  
  cout << "U";
  
  for (i = 0; i < (tx - sx) + 1; i++) {
    cout << "L";
  }
  
  for (i = 0; i < (ty - sy) + 1; i++) {
    cout << "D";
  }
  
  cout << "R";
  
  for (i = 0; i < (tx - sx); i++) {
    cout << "R";
  }
  
  for (i = 0; i < (ty - sy); i++) {
    cout << "U";
  }
  
  cout << "R";
  
  for (i = 0; i < (ty - sy) + 1; i++) {
    cout << "D";
  }
  
  for (i = 0; i < (tx - sx) + 1; i++) {
    cout << "L";
  }
  
  cout << "U";
  
  cout << endl;
  
  return 0;
}

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

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

typedef long long ll;

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

  vector<int> b(n-1);
  rep(i,n-1) cin >> b[i];

  ll ret = b[0] + b[n-2];
  for(int i=1; i<n-1; i++){
    ret += min(b[i-1],b[i]);
  }

  cout << ret << endl;

  return 0;
}

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

signed main() {
  int n; cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];

  int ans = 0;
  for(int i=1; i<n-1; i++) {
    if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
    if(p[i+1] < p[i] && p[i] < p[i-1]) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

const int MAXN=1e5+7;

struct side {
	int from,to,nex;
}edge[MAXN<<1];
int head[MAXN],cntm=0;
void link(int from,int to) {
	edge[++cntm].from=from;
	edge[cntm].to=to;
	edge[cntm].nex=head[from];
	head[from]=cntm;
}

int n;
int col[MAXN],siz[MAXN];
int ans=0;

void dfs(int now,int fa) {
	siz[now]=1;
	for(int i=head[now];i;i=edge[i].nex) {
		if(edge[i].to!=fa) {
			dfs(edge[i].to,now);
			siz[now]+=siz[edge[i].to];
		}
	}
	if(siz[now]==1) return;
	int cnt=0;
	for(int i=head[now],v;i;i=edge[i].nex) {
		v=edge[i].to;
		if(v==fa) continue;
		if(!col[v]) cnt++;
	}
	if(cnt==1) col[now]=1;
	if(cnt>1) ans=1;
	if(now==1&&cnt==0) ans=1;
}

int main() {
	cin>>n;
	for(int i=1,i1,i2;i<n;i++) {
		cin>>i1>>i2;
		link(i1,i2);
		link(i2,i1);
	}
	dfs(1,0);
	if(ans) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

Measured memory_bytes: 7188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int x[] = new int[n];

        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            if (max < x[i]) {
                max = x[i];
            }
        }

        int min = 0;
        int pow = 0;
        int sum = 0;

        for (int i = 0; i <= max; i++) {
            sum = 0;
            for(int j = 0; j <n; j++){
                pow = (x[j] - i)*(x[j] - i);
                sum = sum + pow;
            }
            if(i==0 || min > sum){
                min = sum;
            }
        }

        System.out.println(min);
        sc.close();
    }
}

Measured memory_bytes: 35788
import java.util.*
import kotlin.comparisons.compareBy

fun main(args: Array<String>){
    val (H, W) = readLine()!!.split(" ").map { it.toInt() }
    val S = Array(H){ readLine()!! }

    val d = Array(H){ IntArray(W){ Int.MAX_VALUE / 10} }
    val queue = PriorityQueue<Triple<Int, Int, Int>>(H * W,compareBy { it.third })
    d[0][0] = 1
    queue.add(Triple(0, 0, 1))
    while(queue.isNotEmpty()){
        val e = queue.poll()
        //上
        if(e.first != 0 && S[e.first - 1][e.second] == '.' && d[e.first - 1][e.second] > e.third + 1){
            d[e.first - 1][e.second] = e.third + 1
            queue.add(Triple(e.first - 1, e.second, e.third + 1))
        }
        //下
        if(e.first != H - 1 && S[e.first + 1][e.second] == '.' && d[e.first + 1][e.second] > e.third + 1){
            d[e.first + 1][e.second] = e.third + 1
            queue.add(Triple(e.first + 1, e.second, e.third + 1))
        }
        //左
        if(e.second != 0 && S[e.first][e.second - 1] == '.' && d[e.first][e.second - 1] > e.third + 1){
            d[e.first][e.second - 1] = e.third + 1
            queue.add(Triple(e.first, e.second - 1, e.third + 1))
        }
        //右
        if(e.second != W - 1 && S[e.first][e.second + 1] == '.' && d[e.first][e.second + 1] > e.third + 1){
            d[e.first][e.second + 1] = e.third + 1
            queue.add(Triple(e.first, e.second + 1, e.third + 1))
        }
    }

    val white = S.map { s -> s.filter { c -> c == '.' }.length }.sum()
    println(if(d[H - 1][W - 1] == Int.MAX_VALUE / 10) - 1 else white - d[H - 1][W - 1])
}

Measured memory_bytes: 37648
while True:
    m,f,r=input().split()
    m,f,r=[int(m),int(f),int(r)]
    if m==-1 and f==-1 and r==-1:
        break
    elif m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65 and m+f<80:
        print("B")
    elif m+f>=50 and m+f<65:
        print("C")
    elif m+f>=30 and m+f<50:
        if r>=50:
            print("C")
        else:
            print("D")
    elif m+f<30:
        print("F")


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
struct R
{
    int score;
    string city;
    int id;
    bool operator<(const R& o)const 
    {
        return make_pair(city,-score) < make_pair(o.city,-o.score);
    }
};
int main()
{
    int n;
    cin>>n;
    vector<R> r(n);
    for(int i=0;i<n;++i){
        cin>>r[i].city>>r[i].score;
        r[i].id = i+1;
    }
    sort(r.begin(),r.end());
    for(R x:r)
        cout<<x.id<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
     
    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define loop(i, a, b) for(int i = (a); i < (b); i++)
    #define loopb(i, a, b) for(int i = (a); i > (b); --i)
     
    typedef pair <int,int> ii;
    typedef vector <int> vi;
    typedef vector <ii> vii;
    typedef vector <ll> vl;
     
    const int mod = 1e9+7;
    const ll inf = 2e18+5;
     
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        double p_heads,p_tails;
     
        vector<double> dp(n+1);   //dp[i] is probability of getting i heads so far. Only 1-D array is needed. dp[heads][tails] is not needed because tails=n-heads
        dp[0] = 1;
     
        loop(i,0,n){
            cin>>p_heads;
            p_tails = 1 - p_heads;
            for(int j=i+1; j>=0; j--){
                if (j==0)
                    dp[j] = dp[j]*p_tails;
                else
                    dp[j] = dp[j-1]*p_heads + dp[j]*p_tails;  /*this time heads + *this time tails*/
            }
        }
        double ans = 0;
        int heads, tails;
        for(heads=0; heads<=n; heads++){
            tails = n-heads;
            if(heads>tails)
                ans += dp[heads]; 
        }
        
        printf("%.10lf",ans);
        return 0;
    } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int n;
vector<vector<int>> g(100);

int d[100], f[100];
bool used[100] = {};
int t = 0;

void dfs(int pos){
    d[pos] = ++t;
    used[pos] = true;

    rep(i, g[pos].size()){
        if(used[g[pos][i]])continue;
        dfs(g[pos][i]);
    }

    f[pos] = ++t;
}

int main(){
    cin >> n;

    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            v--;
            g[i].push_back(v);
        }
    }

    rep(i, n){
        if(!used[i])dfs(i);
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int N, M, Q;
vector<int> a(50), b(50), c(50), d(50);

vector<int> A(10);
int ans = 0;

void dfs(int n) {
    if (n == 0) {
        rep(i, M) {
            A[0] = i + 1;
            dfs(n + 1);
        }
        return;
    }
    if (n == N) {
        int score = 0;
        rep(i, Q) {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i]) score += d[i];
        }
        ans = max(ans, score);
        return;
    }
    for (int i = A[n - 1]; i <= M; ++i) {
        A[n] = i;
        dfs(n + 1);
    }
    return;
}

int main() {
    cin >> N >> M >> Q;
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    dfs(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long K =sc.nextLong();

		//テレポート先
		int[] A = new int[N+1];

		for(int i=1; i<=N; i++) {
			A[i] = sc.nextInt();
		}

		int ans = 1;
		long index = 1;

		//loop考慮なし
		if(K <=N) {

			while(index <= K) {
				ans = A[ans];
				index++;
			}

		}
		else {
			//loopを検出
			boolean[] checked = new boolean[N+1];
			Arrays.fill(checked, false);
			List<Integer> loop = new ArrayList<>();
			int before_loop_n = 0;

			while(index <= K) {
				loop.add(ans);
				checked[ans] = true;

				//loopの終わり
				if(checked[A[ans]]) {
					//先頭からA[ans]の前までを削除
					int a = 1;
					while(a != A[ans]) {
						loop.remove(0);
						before_loop_n++;
						a = A[a];
					}
					break;
				}

				ans = A[ans];
				index++;
			}

			ans = 1;
			index = 1;
			if(K <= before_loop_n-1) {
				while(index <= K) {
					ans = A[ans];
					index++;
				}
			}
			else {
				int loop_index = (int)((K - before_loop_n) % loop.size());
				ans = loop.get(loop_index);
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 60640
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int n,m,l,a[][]=new int[100][100],b[][]=new int[100][100],i,j,k;
		long c[][]=new long[100][100];
		n=stdIn.nextInt();
		m=stdIn.nextInt();
		l=stdIn.nextInt();
		for(i=0;i<n;i++)for(j=0;j<m;j++)a[i][j]=stdIn.nextInt();
		for(i=0;i<m;i++)for(j=0;j<l;j++)b[i][j]=stdIn.nextInt();
		for(i=0;i<n;i++)for(j=0;j<l;j++)for(k=0;k<m;k++)c[i][j]+=a[i][k]*b[k][j];
		for(i=0;i<n;i++){
			for(j=0;j<l;j++){
				if(j!=0)System.out.print(" ");
				System.out.print(c[i][j]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 53360
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n,m;
    string s,t;
    in(n,m,s,t);
    int minv=min(n,m);
    ll ans=(ll)n*m/__gcd(n,m);
    int a=ans/n,b=ans/m;
    for(int i=0;i<minv;i++){
        if(i*(ans/m)>n||i*(ans/n)>m)break;
        if(s[i*(ans/m)]!=t[i*(ans/n)]){
            ans=-1;
            break;
        }
    }
    out(ans);
}

Measured memory_bytes: 3920
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s; 
  REP(i,4){
    int count = 0;
    FOR(j,i,4){
      if(s[i] == s[j]){
        count++;
      }else{
        break;
      }
    }
    if(count >= 3){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };

int d[2000][2000];
int main() {
    int h, w;
    cin >> h >> w;
    queue<P> que;
    memset(d, -1, sizeof(d));
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            if(s[j] == '#') {
                que.push(P(j, i));
                d[j][i] = 0;
            }
        }
    }
    int ans = 0;
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        ans = max(ans, d[p.first][p.second]);
        //cout << p.first << " " << p.second << endl;
        rep(k, 4) {
            int nx = p.first + dx[k], ny = p.second + dy[k];
            if(0 <= ny && ny < h && 0 <= nx && nx < w && d[nx][ny] == -1) {
                d[nx][ny] = d[p.first][p.second] + 1;
                que.push(P(nx, ny));
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int ST_MAX = (1 << 20);
const LL INF = 12345678901234567;

template <class T> class ST{
	T x[ST_MAX * 2];
	
	T eval(T a , T b){			//評価
		return max(a,b);
	}
	
	void ren(int a){			//更新
		x[a] = eval(x[2 * a] , x[2 * a + 1]);
		if(a > 0) ren(a / 2);
	}
	
	T read_ST(int a , int b , int e , int s , int f){		//値の取得
		if(e <= s || f <= b) return -INF;
		if(s <= b && e <= f) return x[a];
		return eval(read_ST(2 * a , b , (b + e) / 2 , s , f) , read_ST(2 * a + 1 , (b + e) / 2 , e , s , f));
	}
	
public:
	
	ST(){					//初期化
		fill(x,x+ST_MAX*2,-INF);
	}
	
	void put(int a , T b){	//更新の開始
		x[a + ST_MAX] = b;
		ren((a + ST_MAX) / 2);
	}
	
	T get(int s , int f){	//値の取得の開始
		return read_ST(1 , 0 , ST_MAX , s , f);
	}
};

int N;
LL C;
vector<LL> x;
vector<LL> v;
vector<LL> s;
vector<LL> r;
ST<LL> st;

int main(){
	cin >> N >> C;
	x.resize(N+1);
	v.resize(N+1);
	s.resize(N+2);
	r.resize(N+2);
	x[0] = v[0] = s[0] = r[N+1] = 0;
	repp(i,1,N+1){
		cin >> x[i] >> v[i];
		s[i] = s[i-1] + v[i];
	}
	repm(i,N+1,1) r[i-1] = r[i] + v[i-1];
	LL ans = 0;
	st.put(N+1,0);
	repm(i,N,0) st.put(i,r[i]-(C-x[i]));
	repp(i,0,N+1) ans = max(ans , st.get(i+1,N+2) + s[i] - 2*x[i]);
	repm(i,N,0) st.put(i,r[i]-2*(C-x[i]));
	repp(i,0,N+1) ans = max(ans , st.get(i+1,N+2) + s[i] - x[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19840
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new AOJ0189().doIt();
	}
	
	class AOJ0189{
		void doIt(){
			while(true){
				int n = in.nextInt();
				if(n==0)break;
				int d[][] = new int[10][10];
				for(int i=0;i<10;i++)Arrays.fill(d[i],Integer.MAX_VALUE/2);
				for(int i=0;i<n;i++){
					int a = in.nextInt();
					int b = in.nextInt();
					d[a][b] = d[b][a] = in.nextInt();
				}
				for(int k=0;k<10;k++)for(int i=0;i<10;i++)for(int j=0;j<10;j++){
					d[i][j] = Math.min(d[i][j],d[i][k]+d[k][j]);
				}
				int cnt[] = new int[10];
				
//				for(int i=0;i<10;i++){
//					for(int s=0;s<10;s++)System.out.print(d[i][s]+" ");
//					System.out.println();
//				}
				
				for(int i=0;i<10;i++)for(int s=0;s<10;s++)if(d[i][s]<Integer.MAX_VALUE/2&&i!=s){
					cnt[i]+=d[i][s];
				}
				int result = Integer.MAX_VALUE;
				int num = 0; 
				for(int i=0;i<10;i++)if(cnt[i]>0&&result>cnt[i]){
					result = Math.min(result, cnt[i]);
					num = i;
				}
				System.out.println(num+" "+result);
			}
		}
	}
}

Measured memory_bytes: 19640
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005
ll mod13[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		string s;
		cin>>s;
		ll n=sz(s),i,j,k;

		mod13[0]=1;
		for(i=1;i<N;i++)mod13[i]=(mod13[i-1]*10)%13;

		reverse(all(s));

		vector<ll>a;
		a.pb(0);
		ll rem=0;
		for(i=0;i<n;i++){
			if(s[i]=='?'){
				a.pb(mod13[i]);
			}else{
				rem+=(mod13[i]*(s[i]-'0'));
				rem%=13;
			}
		}

		ll dp[13][sz(a)];
		memset(dp,0,sizeof dp);

		dp[rem][0]=1;

		for(j=0;j<sz(a)-1;j++){
			for(i=0;i<13;i++){
				for(k=0;k<10;k++){
					ll next = (i+a[j+1]*k)%13;
					dp[next][j+1]+=dp[i][j];
					dp[next][j+1]%=hell;
				}
			}
		}

		cout<<dp[5][sz(a)-1];


	}
	return 0;
}

Measured memory_bytes: 12228
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;

string s; int n; int pos;

int digit(){
	int ans = 0;
	while(s[pos] >= '0' && s[pos] <= '9'){ ans = ans * 10 + s[pos] - '0'; pos++; }
	return ans;
}
string alpha(){
	string ans = "";
	while(s[pos] >= 'A' && s[pos] <= 'Z'){ ans += s[pos]; pos++; }
	return ans;
}

struct NODE{
	double len;
	string val;
	vector< pair<double,NODE*> > next;
	NODE(){ len = 0; }
};

NODE* f(){
	double len = 0;
	NODE *c = new NODE;
	while(s[pos] != ')'){
		if( s[pos] >= 'A' && s[pos] <= 'Z'){
			NODE *p = new NODE;
			p->val = alpha();
			p->len = p->val.size();
			c->next.push_back(make_pair(1,p));
			c->len += c->next.back().second->len;
		}else if( s[pos] >= '0' && s[pos] <= '9' ){
			int r = digit();
			if(s[pos] >=  'A'  && s[pos] <= 'Z'){
				NODE *p = new NODE;
				p->val = string(1,s[pos]);
				p->len = p->val.size();
				c->next.push_back(make_pair(r,p));
				c->len += r * c->next.back().second->len;
				pos++;
			}else if(s[pos] == '('){
				pos++;
				c->next.push_back(make_pair(r,f()));
				c->len += r * c->next.back().second->len;
			}else assert(0);
		}
	}
	pos++;
	return c;
}
char get(NODE *h,int n){
	if(h->val != ""){
		return h->val[n];
	}
	int sum = 0;
	for(int i = 0 ; i < h->next.size() ; i++){
		while(h->next[i].first > 0){
			if(n - h->next[i].second->len < 0){
				return get(h->next[i].second,n);
			}else{
				n -= h->next[i].second->len;
			}
			h->next[i].first--;
		}
	}
}
int main(){
	while(cin >> s >> n && s != "0"){
		pos = 0;
		s += ")";
		NODE *h = f();
		if(h->len <= n) cout << "0" << endl;
		else cout << get(h,n) << endl;
	}
}

Measured memory_bytes: 0
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var B = cin.ReadLine;
            string result = string.Empty;

            switch (B)
            {
                case "A":
                    result = "T";
                    break;
                case "T":
                    result = "A";
                    break;
                case "C":
                    result = "G";
                    break;
                case "G":
                    result = "C";
                    break;
                default:
                    break;
            }

            Console.Write(result);
        }

    }
    public class deci
    {
        public bool IsFinish { get; set; } = false;
        public int Len { get; set; }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    int dx = tx-sx, dy = ty-sy;
    
    // 1回目 (sx,sy)→(tx,ty)
    for(int i=0; i<dy; i++)
        cout << "U";
    for(int i=0; i<dx; i++)
        cout << "R";
    
    // (tx,ty)→(sx,sy)
    for(int i=0; i<dy; i++)
        cout << "D";
    for(int i=0; i<dx; i++)
        cout << "L";
    
    // 2回目
    cout << "L";
    for(int i=0; i<=dy; i++)
        cout << "U";
    for(int i=0; i<=dx; i++)
        cout << "R";
    cout << "D";
    
    cout << "R";
    for(int i=0; i<=dy; i++)
        cout << "D";
    for(int i=0; i<=dx; i++)
        cout << "L";
    cout << "U";
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < N; i++) {
			int x= sc.nextInt();
			sum += 2* Math.min(x, K-x);
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 27152
#include <iostream>
#include <cmath>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int y;
		cin >> y;
		int ans = 0;
		double max = 0;
		for(int i = 0; i < n; ++i)
		{
			int b, r, t;
			cin >> b >> r >> t;
			double sum = 1;
			if(t == 1)
			{
				sum = 1 + y * r / 100.0;
			}
			else
			{
				sum = pow(1 + r / 100.0, y);
			}
			if(sum > max)
			{
				ans = b;
				max = sum;
			}
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1164
#include <bits/stdc++.h>
inline long long read();
using namespace std;
int mapp[4][105],mx[4][105];
int main()
{
	int n=read();
	for(int j=1;j<=2;j++)
	for(int i=1;i<=n;i++)
	{
		mapp[j][i]=read();
	}
	for(int i=2;i>=1;i--)
	{
		for(int j=n;j>=1;j--)
		{
			mx[i][j]=max(mx[i+1][j],mx[i][j+1])+mapp[i][j];
		}
	}
	cout<<mx[1][1];
}
inline long long read()
{
    register long long x=0,k=1;
    char c;
    c=getchar();
    while(c<'0'||c>'9'){if(c=='-')k=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*k;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int x_n[n], y_n[m];
    rep(i, n) cin >> x_n[i];
    rep(i, m) cin >> y_n[i];

    bool last_flag=false;
    for(int i=x+1; i<=y; i++){
        bool flag=true;
        rep(j, n) if(x_n[j]>=i) flag=false;
        rep(z, m) if(y_n[z]<i) flag=false;
        if(flag==true) {last_flag=true;}
    }
    if(x>y) last_flag=false;
    
    if(last_flag==true) out("No War");
    else out("War");
}

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

int n, a[100010];
int ans;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i) scanf("%d", &a[i]);
	std::sort(a, a+n);
	int t = 0, num = 0;
	for(int i=0; i<n; ++i){
		if(t != a[i]){
			if(num % 2 == 1) ++ans;
			t = a[i];
			num = 1;
		}else{
			++num;
		}
	}
	if(num % 2 == 1) ++ans;
	printf("%d\n", ans);
}

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

int x[]={-1,0,1,0};
int y[]={0,1,0,-1};

int main(){
	int N;
	while(cin>>N,N){
		int data[210][2];
		data[0][0]=data[0][1]=0;
		int Xmin=0,Xmax=0,Ymin=0,Ymax=0;
		
		for(int i=1,A,B;i<N;i++){
			cin>>A>>B;
			data[i][0]=data[A][0]+x[B];
			data[i][1]=data[A][1]+y[B];
			Xmin=min(Xmin,data[i][0]);
			Xmax=max(Xmax,data[i][0]);
			Ymin=min(Ymin,data[i][1]);
			Ymax=max(Ymax,data[i][1]);
		}
		cout<<Xmax-Xmin+1<<" "<<Ymax-Ymin+1<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1160
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		double[] d = new double[50];

		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		int n = str.length();

		String ans = "";
		for (int i=0; i<n; i++) {
			ans = ans + "x";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main (){
    int N, P; cin >> N >> P;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        if(a%2){
            cout << (ll)pow(2, N-1) << endl;
            return 0;
        }
    }
    if(P) cout << 0 << endl;
    else cout << (ll)pow(2, N) << endl;
    return 0;
}



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

static const ULL M = 1000000007;

struct Problem {
public:

	string S;
	UL D;
	ULL dp[100] = {};
	ULL buf[100] = {};
	UL sum = 0;

	void Solve() {
		cin >> S >> D;
		for (char c : S) {
			UL d = c - '0';
			rep(i, D) buf[i] = 0;
			rep(i, D) rep(d, 10) buf[(i + d) % D] += dp[i];
			rep(p, d) buf[(sum + p) % D] += 1;
			rep(i, D) dp[i] = buf[i] % M;
			sum += d;
		}
		dp[0] = (dp[0] + M - 1) % M;
		dp[sum % D] = (dp[sum % D] + 1) % M;
		printf("%llu", dp[0]);
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


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

using namespace std;
#define ll long long
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;
typedef pair<int,int>           PI;
typedef pair<ll,ll>             PL;
typedef vector<PI>               vip; 
typedef vector<int>             vi;
typedef vector<vi>              vvi;






int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vi c(16);
    int n, m, j, k, d, x, y, p;
    while(cin >> n >> m,n){
        REP(i,3){
            for(cin >> j; j>0; --j){
                cin >> k;
                c[n-k] = i;
            }
        }

        p= 0;
        x=0;
        for(int i = n-1; i>=0; --i){
            d = abs(p - c[i]);//pはいる位置
            x += pow(3,i) * d;
            if(d == 1){
                p = 2-p;
            }
        }

        y = pow(3,n) - 1 - x;
        int ans = min(x,y);
        if(ans <= m) cout << ans << endl;
        else cout << -1 << endl;
    }









    return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; i++) {
    int rev = 0;
    for (int j = i; j != 0; j /= 10) {
      rev = rev * 10 + j % 10;
    }
    if (rev == i) {
      ans++;
    }
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N; cin>>N;
  bool finish=false;
  for(int i=1;i<3501;i++){
    for(int j=1;j<3501;j++){
      if((4*i*j-N*i-N*j)>0){
        if((N*i*j)%(4*i*j-N*i-N*j)==0){
          cout<<i<<' '<<j<<' '<<(N*i*j)/(4*i*j-N*i-N*j);
          finish=true;
          break;
        }
      }
    }
    if(finish) break;
  }  
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    if (n == 1)cout << "1\n0";
    else if (n == 2)cout << "2\n00\n1\n";
    else {
        cout << n - 1 << "\n";
        FOR(i, 0, n - 1) {
            cout << 1;
            FOR(j, 0, i)cout << 0;
            cout << "1\n";
        }
    }
}


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

    string a, b, c;
    cin >> a >> b >> c;

    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;


}

Measured memory_bytes: 256
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
using namespace std;
  
#define int long long int 
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<vi> vvi;
const int mod = 1e9 + 7; 

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define TC int t; cin >> t; while (t--) 

int ans(int in[], int n, int dp[], int k) {
	if(n <= 0) return INT_MAX;
	if(n == 1) return dp[n] = 0;
	if(dp[n] != -1) return dp[n];
	int minn = INT_MAX;
	for(int i = 1; i <= k; i++) {
		int j = ans(in + i, n - i, dp, k) + abs(in[0] - in[i]);
		minn = min(minn, j);
	} 
	dp[n] = minn;
	return dp[n]; 
}

void Panda() {
    int n, k;
    cin >> n >> k;
    int in[n], dp[n + 1];
    for(int i = 0 ; i < n; i++) cin >> in[i], dp[i] = -1;
    dp[n] = -1;
    cout << ans(in, n, dp, k)<< endl;
}
  
int32_t main() {
 
    FAST;

  
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int x;
   cin >> x;
   int ans = (x/500)*1000;
   x %= 500;
   ans += (x/5)*5;
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int main() {
    char a;
    cin >> a;

    if (0 <= a - 'a' && a - 'a' <= 26) {
        cout << 'a' << endl;
    }
    else {
        cout << 'A' << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
for i in range(h):
    for j in range(w):
        a[i][j]%=2
#print(a)
#do a snake traversel
hold=0
ans=[]
for i in range(h):
    if i&1:
        for j in range(w-1,-1,-1):
            #print(i,j,end=' curr \n')
            if hold:
                if a[i][j]:
                    a[i][j]=0
                    hold=0
                else:
                    if j==0 and i!=h-1:
#                        print(i,j,i+1,j)#move down
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j>0:
#                        print(i,j,i,j-1)#move left
                        ans.append((i+1,j+1,i+1,j))
            else: #u r holding nothing 
                if a[i][j]:
                    hold=1
                    a[i][j]=0
                    if j==0 and i!=h-1:
 #                       print(i,j,i+1,j)#move down
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j>0:
  #                      print(i,j,i,j-1)#move left
                        ans.append((i+1,j+1,i+1,j))
    else:
        for j in range(w):
            if hold:
                if a[i][j]:
                    a[i][j]=0
                    hold=0
                else:
                    if j==w-1 and i!=h-1:
   #                     print(i,j,i+1,j)#move down
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j!=w-1:
    #                    print(i,j,i,j+1)#move right
                        ans.append((i+1,j+1,i+1,j+2))
            else:
                if a[i][j]:
                    hold=1
                    a[i][j]=0
                    if j==w-1 and i!=h-1:
     #                   print(i,j,i+1,j)#move down
                        ans.append((i+1,j+1,i+2,j+1))
                    elif j!=w-1:
      #                  print(i,j,i,j+1)#move right
                        ans.append((i+1,j+1,i+1,j+2))
print(len(ans))
for i in ans:
    print(' '.join(map(str,i)))
#print(a,end=' updated\n')    


Measured memory_bytes: 26220