akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int a=sc.nextInt();
    if(n%500<=a){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23124
n=int(input())
h = list(map(int,input().split()))

tem =0

for i in range(n):

    if(i==0):
        pass
    elif( int(h[-(i+1)]) > 1 + int(h[-i]) - tem ):
        answer = "No"
        break
    elif(int(h[-(i+1)]) == 1 + int(h[-i]) - tem  ):
        tem = 1
    else:
        tem = 0

    answer = "Yes"


print(answer)

Measured memory_bytes: 14396
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            int ans = 0;

            int len = S.length();

            for (int i = len - 2; i > 0; i -= 2) {
                String tmp = S.substring(0, len - i);
                if (tmp.length() % 2 != 0) continue;
                String tmphalf = tmp.substring(0, tmp.length() / 2);
                if ((tmphalf + tmphalf).equals(tmp)) {
                    ans = tmp.length();
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define veci vector<int>
#define vecl vector<ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
#define pui pair<int, pair<int,int> >
using namespace std;

 
 
void solve(){
    
   int n;
   cin>>n;


   int val = n%10;

   if(val == 2 || val == 4|| val ==5 || val ==7 || val ==9) {
       cout<<"hon";
   } else if(val == 3) {
       cout<<"bon";
   } else {
       cout<<"pon";
   }

}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(10);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}



Measured memory_bytes: 3616
import sys
my_input = sys.stdin.readline


class BinarySearchTree:
    class Node:
        def __init__(self, key):
            __slots__ = ['key', 'left', 'right', 'parent']
            self.key = key
            self.left = None
            self.right = None
            self.parent = None

    def __init__(self):
        self.root = None

    def insert(self, target_key):
        parent = None
        attention = self.root
        target = self.Node(target_key)

        while attention:
            parent = attention
            if target.key < attention.key:
                attention = attention.left
            else:
                attention = attention.right
        target.parent = parent

        if parent is None:
            self.root = target
        elif target.key < parent.key:
            parent.left = target
        else:
            parent.right = target

    def find(self, target_key):
        attention = self.root
        while attention:
            if attention and (attention.key == target_key):
                return attention

            if target_key < attention.key:
                attention = attention.left
            else:
                attention = attention.right

        return False

    def preorder_walk(self, node):
        if node is None:
            return []
        return [node.key] + self.preorder_walk(node.left) + self.preorder_walk(node.right)

    def inorder_walk(self, node):
        if node is None:
            return []
        return self.inorder_walk(node.left) + [node.key] + self.inorder_walk(node.right)


N = int(my_input())
BST = BinarySearchTree()
for _ in range(N):
    command = my_input().split()
    if command[0] == 'insert':
        BST.insert(int(command[1]))

    elif command[0] == 'find':
        print('yes' if BST.find(int(command[1])) else 'no')

    elif command[0] == 'print':
        print(' ' + ' '.join(map(str, BST.inorder_walk(BST.root))))
        print(' ' + ' '.join(map(str, BST.preorder_walk(BST.root))))



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

int main() {
  int N;
  cin >> N;
  int A = 0, B = 0, AB = 0, BA = 0, ans = 0;
  string s;
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s[0] == 'B') B++;
    if (s[s.length() - 1] == 'A') A++;
    if (s[0] == 'B' && s[s.length() - 1] == 'A') BA++;
    for (unsigned int j = 0; j < s.length(); j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') AB++;
    }
  }
  if (BA > 0) {
    ans = BA;
    if (A - BA > 0) {
      A -= 1;
      ans++;
    }
    if (B - BA > 0) {
      ans++;
      B -= 1;
    }
    ans -= 1;
  }
  ans += max(0, min(A - BA, B - BA));
  ans += AB;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N, L;
    cin >> N >> L;
    int sum = 0;
    FOR(i, L, N + L) sum += i;
    
    if(0 < L)
        cout << sum - L;
    else if(N + L - 1 < 0)
        cout << sum - N - L + 1;
    else
        cout << sum;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ff(i,a,b) for(int i = a; i < b; i++)
#define fb(i,a,b) for(int i = a; i > b; i--)
#define MOD 1000000007


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


void solve(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int flag=0;
	while(1){
		if(b>a) break;
		b*=2;
		k--;
		if(k==0){
			flag=1;
			break;
		}
	}
	//if(flag&&c<=b) cout<<"No";
	//flag=0;
	c*=pow(2,k);
	if(c>b&&b>a) cout<<"Yes";
	else cout<<"No";
}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	//int t;
    //cin>>t;
	//while(t--)
		solve();
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 4184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int calc_digit(int);

int main(){
	int a,b;

	while(1){
		if(scanf("%d %d" ,&a,&b) == EOF){
			break;
		}
		printf("%d\n",calc_digit(a+b));
	}

	return 0;
}

int calc_digit(int num){
	char str[256];

	// 数字を文字に変換 120 → "120"
	sprintf(str, "%d", num);

	// 文字の長さ == 桁数
	return strlen(str);
}

Measured memory_bytes: 612
import java.util.*;

public class Main {

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

		while(true){
			int r = sc.nextInt();
			int c = sc.nextInt();
			if(r==0 && c==0) break;
			if(r%2==1 && c%2==1) System.out.println("no");
			else System.out.println("yes");
		}
	}

}

Measured memory_bytes: 19036
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a*b%2==1) {
			System.out.println("Odd");
		} else {
			System.out.println("Even");
		}
	}
}

Measured memory_bytes: 21588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var hw = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var h = hw[0];
            var w = hw[1];

            var maps = new bool[h][];

            string result = "Possible";

            for (int i = 0; i < h; i++) {
                maps[i] = Console.ReadLine().Select(x => x == '#').ToArray();
            }

            var lastIndex = 0;

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (maps[i][j]) {
                        if(j < lastIndex) {
                            result = "Impossible";
                            Console.WriteLine(result);
                            Console.Out.Flush();
                            return;
                        }

                        lastIndex = j;
                    }
                }
            }
            /*
            for (int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    if(i == h - 1 && j == w - 1) {
                        continue;
                    }

                    if (maps[i][j]) {
                        var mapa = i != h - 1 ? maps[i + 1][j] : false;
                        var mapb = j != w - 1 ? maps[i][j + 1] : false;

                        var aa = mapa && mapb;
                        var bb = mapa || mapb;

                        if(aa || (bb == false)) {
                            result = "Impossible";
                            Console.WriteLine(result);
                            Console.Out.Flush();
                            return;
                        }
                    }
                }
            }
            */
            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

int main(){
  long long int x=2,y=1,N,j,k;
  cin >> N;
  for(int i=1;i<N;i++){
    j=x;
    k=y;
    y=j+k;
    x=k;
  }
  if(N==1)cout << 1 << endl;
  else cout << y << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int chk (ll k, const ll t){
  int rtn = 0;
  while( k%t == 0 && k >= t ) {
    k /= t;
    rtn++;
  }
  return rtn;
}

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

  int ans = 0;
  for(int i=0; i<N; i++) {
    ans += chk(a[i],2);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> bs(n);
  for(Int i=0;i+1<n;i++) cin>>bs[i];
  bs[n-1]=bs[n-2];

  Int ans=bs[0];
  for(Int i=0;i+1<n;i++) ans+=min(bs[i],bs[i+1]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int A = int.Parse(str[0]);
        int B = int.Parse(str[1]);

        if(A + B >= 10){
            Console.WriteLine("error");
        }else{
            Console.WriteLine(A + B);
        }
    }
}



Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        WriteLine((cin.Nextint + cin.Nextint) % 24);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11216
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a - b+1) * (a - c + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<ll> dp(n, INT_MAX);
	dp[0]=0;
	ll sum=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+2;j++){
			dp[j]=min(dp[j], dp[i]+abs(a[j]-a[i]));
		}
	}
	cout<<dp[n-1]<<endl;		
	// your code goes here
	return 0;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
using ll = long long;
ll dp[55][5];  // dp[i][j]=風船をj個盛った状態でi個目の風船を受け取るまでの移動距離
int X[55], T[55];

const ll INF = 1e18;
stack<int> stk[101];
bool solve() {
    int N, D;
    cin >> N >> D;
    if (N == 0 && D == 0) return false;
    vector<int> sum(N);
    REP(i, N) {
        while (!stk[i].empty()) stk[i].pop();
    }
    REP(i, N) {
        int m;
        cin >> m;
        REP(_, m) {
            int x;
            cin >> x;
            sum[i] += x;
            stk[i].push(x);
        }
    }
    // int mn = 1e9;
    // REP(i, N) { mn = min(mn, sum[i]); }

    bool done = false;
    bool found = true;
    while (found) {
        found = false;
        bool allempty = true;
        REP(i, N) {
            if (stk[i].empty()) continue;
            allempty = false;
            int x = stk[i].top();
            bool ok = true;
            REP(j, N) {
                if (j == i) continue;
                if (abs((sum[i] - x) - sum[j]) > D) ok = false;
            }
            if (ok) {
                found = true;
                sum[i] -= x;
                stk[i].pop();
            }
        }
        // mn = 1e9;
        // REP(i, N) { mn = min(mn, sum[i]); }
        if (allempty) {
            done = true;
            break;
        }
    }
    if (done)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return true;
}

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


Measured memory_bytes: 3268
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  int A,B,C; cin >> A >> B >> C;
  cout << min(B/A,C) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vl a;
vvl dp;
vl sum;

long dfs(int l, int r){
  if(dp[l][r] != -1) return dp[l][r];
  if(l == r) return dp[l][r] = 0;
  long ret = 1e16;
  long f = sum[r+1] - sum[l];
  REP(i,l,r){
    ret = min(ret, dfs(l,i) + dfs(i+1,r) + f);
  }
  return dp[l][r] = ret;
}

int main(){
  int n;
  cin >> n;
  a = vl(n);
  sum = vl(n+1,0);
  rep(i,n) {
    cin >> a[i];
    sum[i+1] = sum[i] + a[i];
  }
  dp = vvl(n,vl(n,-1));
  cout << dfs(0,n-1) << endl;
}

Measured memory_bytes: 4888
S = input()
k = []
skip = False
skipped = False

for i, s in enumerate(S):
  if skip:
    skip = False
    skipped = True
    continue
  if skipped:
    skipped = False
    k.append(S[i])
  elif i < len(S) - 1:
    if S[i] == S[i + 1]:
      k.append(S[i] + S[i + 1])
      skip = True
    else:
      k.append(S[i])
  else:
    k.append(S[i])

print(len(k))

Measured memory_bytes: 8296
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0 ; i < n ; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int ans = 1;
    bool flag = false;
    for(int i = 0 ; i < n - 1 ; i++){
        if(A[i] == A[i+1] && !flag){
            ans--;
            flag = true;
            continue;
        }else{
            ans++;
        }
        flag = false;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll MOD=1e9+7;
const ll INF=1ll<<60;

//
//　定数, 変数 *********************************************
int A,B,H,M;
static const double pi = 3.14159265358979 ;
// *********************************************************
int main(){

    // 入力スタンダード
    cin >> A >> B >>H >> M;
    
    double akaku, bkaku, aida;

    bkaku = 6 * M;
    akaku = 30*H + 0.5*M;
    aida = abs(akaku-bkaku);
    if(aida>180){
        aida = 360 - aida;
    }

    if(aida==0){
        cout << abs(A-B) << endl;
    }else if(aida==180){
        cout << A+B << endl;
    }else{
        cout << fixed << setprecision(10) << sqrt(A*A + B*B - 2*A*B*cosl(pi * aida / 180)) << endl;
    }


    //**************
    //cout << akaku << " " << bkaku << " " << aida <<endl;

    return 0;
}

Measured memory_bytes: 4152
#include<cstdio>
#include<cmath>

int main(){
	double x = 0, y = 0;
	double a,b,d = 90;
	scanf("%lf,%lf", &a, &b);
	while(a || b){
		y += a * sin(d * M_PI / 180);
		x += a * cos(d * M_PI / 180);
		d -= b;
		scanf("%lf,%lf", &a, &b);
	}
	printf("%d\n%d\n", (int)x, (int)y);
	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#define ll long long
using namespace std;
ll n,m;
ll a[55];
ll dfs(ll x,ll y)
{
	//cout <<x<<" "<<y<<" "<<a[x]<<"\n";
	if (y<=x) return 0;
	else if (x==0) return 1;
	else
	{
	    if (y-1<=a[x-1]) return dfs(x-1,y-1);
	    else if (y-1==a[x-1]+1) return dfs(x-1,y-2)+1;
	    else if (y!=a[x]) return dfs(x-1,a[x-1])+1+dfs(x-1,y-a[x-1]-2);
		else return dfs(x-1,a[x-1])*2+1;
	}
}
int main()
{
	cin >>n>>m;
	a[0]=1;
	for (int i=1;i<=n;i++) a[i]=a[i-1]*2+3;
	cout <<dfs(n,m);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
back = -2
for i in range(N):
    ans += B[A[i]-1]
    if i >= 1 and back +1 == A[i]:
        ans += C[back-1]
    back = A[i]
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pt pair<ll , ll>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
#define double long double
int MAGIC = 400;
const int mod = 998244353;

const int MAX = 500005;
int a[200005];
int main()
{
	int n;
	cin >> n;
	ll total = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		total += a[i];
	}
	ll tot2 = 0;
	ll ans = mod * (ll)mod;
	for(int i = 0; i < n; i++)
	{
		tot2 += a[i];
		ans = min(ans , abs(total - 2 * tot2));
	}
	cout << ans;
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {
    for (int u: to[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;

    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(N);

    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);
    rep(i, N) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 23424
#include <iostream>
#include <stdio.h>
#include <string>
#include <memory.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <time.h>
#include <assert.h>
#include <cmath>
#include <stack>
#include <string.h>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	scanf("%d", &n);
	vector<pair<int, int> > w;
	for (int i = 0; i < n; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		w.push_back({ l,r });
	}
	ll res = 1e18;
	for (int it = 0; it < 2; ++it) {
		ll kk = 0;
		for (int jt = 0; jt < 2; ++jt) {
			ll k = 0;
			ll cur = 0;
			multiset<pair<int, int> > mn, mx;
			for (int i = 0; i < n; ++i) {
				int l = w[i].first;
				int r = w[i].second;
				if (it == 1) {
					l = -l;
					r = -r;
					swap(l, r);
				}
				mx.insert(make_pair(l, r));
				mn.insert(make_pair(r, l));
			}
			for (int i = 0; i < n; ++i) {
				if (((i % 2) ^ jt) == 0) {
					auto u = *--mx.end();
					mx.erase(--mx.end());
					int l = u.first;
					int r = u.second;
					mn.erase(mn.find(make_pair(r, l)));
					if (cur > r) {
						k += cur - r;
						cur = r;
					}
					else if (l > cur) {
						k += l - cur;
						cur = l;
					}
				}
				else {
					auto u = *mn.begin();
					mn.erase(mn.begin());
					int l = u.second;
					int r = u.first;
					mx.erase(mx.find(make_pair(l, r)));
					if (cur > r) {
						k += cur - r;
						cur = r;
					}
					else if (l > cur) {
						k += l - cur;
						cur = l;
					}
				}
			}
			k += abs(cur);
			kk = max(kk, k);
		}
		res = min(res, kk);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 12404
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ins(S);
  rep(i , sz(S)){
    if(i%2 == 0 && S[i] == 'L') die("No");
    if(i%2 == 1 && S[i] == 'R') die("No");
  }
  die("Yes");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x,a;
	scanf("%d",&x);
	a=x;
	if(x>=7){
		a=x%7;
	}
	if(a==0){
		printf("thu\n");
	}
	if(a==1){
		printf("fri\n");
	}
	if(a==2){
	    printf("sat\n");
	}
	if(a==3){
		printf("sun\n");
	}
	if(a==4){
		printf("mon\n");
	}
	if(a==5){
		printf("tue\n");
	}
	if(a==6){
		printf("wed\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)

namespace FastIO {
struct Strs {
  char strs[10000 * 4];
  constexpr Strs() : strs() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
} constexpr strs;
static constexpr size_t buf_size = 1 << 17;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e5) return 6;
  if (x >= (long long)1e4) return 5;
  if (x >= (long long)1e3) return 4;
  if (x >= (long long)1e2) return 3;
  if (x >= (long long)1e1) return 2;
  return 1;
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  if (pt_in + 32 > tail_in) load();
  char c;
  bool minus = 0;
  x = 0;
  scan(c);
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
  if (minus) x = -x;
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
inline void print(const char* s) {
  if (pt_out > buf_size - 32) flush();
  for (int i = 0; s[i] != 0; ++i) print(s[i]);
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

int main() {
  int N;
  scan(N);
  int A[200000], B[200000];
  REP(i, N) scan(A[i]);
  REP(i, N) scan(B[N - 1 - i]);
  int ngs[200000], oks[200000];
  int ngp = 0, okp = 0;
  int ngx = -1;
  REP(i, N) {
    if (A[i] == B[i]) {
      ngs[ngp++] = i;
      ngx = A[i];
    }
  }
  REP(i, N) if (A[i] != ngx && B[i] != ngx) oks[okp++] = i;
  REP(j, ngp) {
    int i = ngs[j];
    if (okp == 0) {
      println("No");
      return 0;
    }
    int target = oks[--okp];
    swap(B[i], B[target]);
  }
  println("Yes");
  REP(i, N) println(B[i]);
  return 0;
}


Measured memory_bytes: 6268
from operator import itemgetter
n=int(input())
y,s=list(),list()
for i in range(1,n+1):
	S=input().split()
	S[1]=int(S[1])
	S.append(i)
	s.append(S)
y=sorted(s,key=itemgetter(0))
for i in range(n):
	c=0
	for j in range(1,n):
		if((y[j-1][0]==y[j][0])&(y[j-1][1]<y[j][1])):
			y[j-1],y[j]=y[j],y[j-1]
			c=1
	if c==0:break
for i in range(n):
	print(y[i][2])

Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;

int main()
{
	int a, b, h, m;
	scanf ("%d %d %d %d", &a, &b, &h, &m);

	double pi = acos(-1.0);
	double ax = a * cos(2 * pi * (h * 60 + m) / 720);
	double ay = a * sin(2 * pi * (h * 60 + m) / 720);
	double bx = b * cos(2 * pi * m / 60);
	double by = b * sin(2 * pi * m / 60);

	printf ("%.15lf\n", hypot(ax - bx, ay - by));

	return 0;
}

Measured memory_bytes: 2504
#include <cstdio>
#include <queue>
#include <utility>
#include <set>
#include <iostream>
using namespace std;

int H, W, K;
char board[810][810];
int visited[810][810];
const int INF = 1 << 29;

struct Elem {
    int x, y, rest;
};

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

int main() {
    scanf("%d%d%d", &H, &W, &K);

    int sx = -1, sy = -1;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            scanf(" %c", &board[i][j]);

            if(board[i][j] == 'S') {
                sx = i, sy = j;
            }
        }
    }

    queue< Elem > que;
    que.push( Elem{sx, sy, K} );

    set< pair<int, int> > init_vs;
    fill(visited[0], visited[810], INF);
    visited[sx][sy] = 0;

    while(que.size()) {
        Elem cur = que.front(); que.pop();
        init_vs.insert(make_pair(cur.x, cur.y));
        // printf("insert: x = %d, y = %d, cost = %d\n", cur.x, cur.y, visited[cur.x][cur.y]);
        if(cur.rest == 0) continue;

        for(int k=0; k<4; k++) {
            int nx = cur.x + dx[k], ny = cur.y + dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(board[nx][ny] == '#') continue;

            if(visited[nx][ny] != INF) continue;
            visited[nx][ny] = visited[cur.x][cur.y] + 1;
            que.push(Elem{nx, ny, cur.rest - 1});
        }
    }

    for(auto x : init_vs) {
        visited[x.first][x.second] = 0;
        que.push(Elem{x.first, x.second, 0});
    }
    while(que.size()) {
        Elem cur = que.front(); que.pop();

        for(int k=0; k<4; k++) {
            int nx = cur.x + dx[k], ny = cur.y + dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(visited[nx][ny] != INF) continue;
            visited[nx][ny] = visited[cur.x][cur.y] + 1;
            que.push(Elem{nx, ny, 0});
        }
    }

    int ans = INF;
    for(int i=0; i<W; i++) {
        // printf("pat a: val_l = %d, val_r = %d\n", visited[0][i], visited[H-1][i]);
        ans = min(ans, (visited[0  ][i] + K - 1) / K + 1);
        ans = min(ans, (visited[H-1][i] + K - 1) / K + 1);
    }
    for(int i=0; i<H; i++) {
        // printf("pat b: val_l = %d, val_r = %d\n", visited[i][0], visited[i][W-1]);
        ans = min(ans, (visited[i][0  ] + K - 1) / K + 1);
        ans = min(ans, (visited[i][W-1] + K - 1) / K + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 40848
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
template<int Size>
struct UF{
	UF(){
		for(int i=0;i<Size;i++){
			rep[i]=i;
		}
	}
	int find(int a){
		while(a!=rep[a]){
			a=rep[a]=rep[rep[a]];
		}
		return a;
	}

	int rep[Size];
	bool uni(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b){
			return false;
		}
		rep[a]=b;
		return true;
	}
};

const int L=2e5+1;
int main() {
	UF<L> a,b;
	int N,K,L;
	cin >> N >> K >> L;
	for(int i=0;i<K;i++){
		int p,q;
		cin >> p >> q;
		a.uni(p,q);
	}
	for(int i=0;i<L;i++){
		int p,q;
		cin >> p >> q;
		b.uni(p,q);
	}
	map<P,int> cs;
	for(int i=1;i<=N;i++){
		cs[P(a.find(i),b.find(i))]++;
	}
	auto sp="";
	for(int i=1;i<=N;i++){
		cout << sp << cs[P(a.find(i),b.find(i))];
		sp=" ";
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 10752
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

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

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::string str;
	std::cin >> n >> str;
	int ans = 0;
	for(auto c : str) {
		ans += (c == 'R' ? 1 : -1);
	}
	std::cout << (ans > 0 ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  for (int i = n; i < 1000; i++) {
    if (i / 100 == i % 10 && i % 10 == (i / 10) % 10) {
      P(i);
      return 0;
    }
  }
  return 0;
}



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

using namespace std;

int w[1001],W,n;
int c[1001];
long long dp[101][100001];

long long rec(int pos, int curr){
    if(pos>=n){
        return 0;
    }
    if(~dp[pos][curr])return dp[pos][curr];
    long long ans = rec(pos+1,curr);
    if(curr+w[pos]<=W){
        ans = max(ans,rec(pos+1,curr+w[pos])+c[pos]);
    }
    return dp[pos][curr]=ans;
}

int main()
{
   cin>>n>>W;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<n;++i){
       cin>>w[i]>>c[i];
   }
   cout<<rec(0,0);
   return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;


int main(){
    ll r, D, x; cin >> r >> D >> x;
    ll res = x;
    rep(i, 10) {
        res = r * res - D;
        cout << res << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int x[10][10];
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n+1){
		int z=i,a=i%10,b;
		while(z>=10){
			z/=10;
		}
		b=z;
		if(!a||!b)continue;
		x[a][b]++;
	}
	f(i,n+1){
		int z=i,a=i%10,b;
		while(z>=10){
			z/=10;
		}
		b=z;
		if(!a||!b)continue;
		ans+=x[b][a];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
}

const int INF = 1e9, MAXN = 1e5 + 10;                 	

void solve() {                         
	int n;
	cin >> n;
	vector<int> a(n);
	for (int j = 0; j < n; ++j) {
	 	cin >> a[j];
	}

	int i = 0, ans = 0;
	while (i < n - 1) {
		int prev = i;
	 	while (i < n - 1 && a[i] >= a[i + 1]) {
			i++;
	   	}
	   	ans = max(ans, i - prev);
	   	i++;
	}

	cout << ans << endl;
}	


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

using namespace std;

typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    vector<P> sv(N);
    int sn;
    for (int i = 0; i < N; i++) {
        cin >> sn;
        sv[i] = {sn, i+1};
    }

    sort(sv.begin(), sv.end(), [](const P& l, const P&r){return l.first < r.first;});

    for (int i = 0; i < N; i++) {
        cout << sv[i].second << " ";
    }

    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,x;cin>>n>>x;
    vector<vector<ll> > dp(vector<vector<ll> >(n+1,vector<ll>(1<<9)));
    vector<vector<ll> >dp2(vector<vector<ll> >(n+1,vector<ll>(1<<9)));
    dp2[0][0]=1;
    rep(i,x+1){
        rep(k,1<<9){
            rep(j,n+1){
                dp[j][k]=dp2[j][k];
                dp2[j][k]=0;
            }
        }
        rep(k,1<<9){
            rep(j,n+1){
                dp2[j][k]=(dp2[j][k]+dp[j][k])%mod;
                if(j<n)dp2[j+1][k^i]=(dp2[j+1][k^i]+dp[j][k])%mod;
            }
        }
        rep(j,1<<9){
            REP(k,2,n+1){
                dp2[k][j]=(dp2[k][j]+dp2[k-2][j])%mod;
            }
        }
    }
    rep(j,x+1){
        rep(k,n+1){
            //cout<<k<<' '<<j<<' '<<dp2[k][j]<<endl;
        }
    }
    cout<<dp2[n][x]<<endl;
}


Measured memory_bytes: 5000
<?php
error_reporting(0);
//$N = explode(" ",trim(fgets(STDIN)));
$N[] = trim(fgets(STDIN));
$N[] = trim(fgets(STDIN));
$N[] = trim(fgets(STDIN));
//list($H,$W) = explode(" ",trim(fgets(STDIN)));
printf("%s%s%s\n",$N[0][0],$N[1][1],$N[2][2]);


Measured memory_bytes: 3700
#include <iostream>
#include <string.h>
#include <string>
using namespace std;

void b_break_number(void) {
	int n,m;
	cin >> n;
	int cnt = 0;
	int cnt_max = 0;
	int n_max=1;
	for (int i = 1; i <= n; i++) {
		m = i;
		cnt = 0;
		while (true) {
			if ((m & 0x1) == 0x1) break;
			m = m >> 1;
			cnt++;
		}
		if (cnt > cnt_max) {
			cnt_max = cnt;
			n_max = i;
		}
	}
	cout << n_max << endl;
}

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  uint64_t N, A, B;
  cin >> N >> A >> B;

  uint64_t q = N / (A + B);
  uint64_t r = N % (A + B);
  uint64_t result = 0;
  result += A * q;
  if (r >= A) {
    result += A;
  }
  else {
    result += r;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 0;
		int point[][] = new int[n][3];
		int sum[] = new int[n];
		for(int i = 0;i < n;i++){
			for(int k = 0;k < 3;k++){
				point[i][k] = sc.nextInt();
			}
			sum[i] = 0;
		}
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < n;j++){
				cnt = 0;
				for(int k = 0;k < n;k++){
					if(point[j][i] == point[k][i]) cnt++;
				}
				if(cnt == 1) sum[j] += point[j][i];
			}
		}
		for(int i = 0;i < n;i++){
			System.out.println(sum[i]);
		}
	}
}

Measured memory_bytes: 28852
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
int A[999999], W[999999];
long long merge_and_count(int l, int r) { // range [l,r)
	if (l+1 >= r) return 0; // empty
	if (l+2 == r) { // [l,r) == [l,l+1] 要素2つだけ
		if (A[l] <= A[l+1]) return 0; // 逆転はなし
		std::swap(A[l], A[l+1]);
		return 1; // 逆転一つ
	}
	int m = (l+r)/2; // [l,r) == [l,m) + [m,r)
	long long cl = merge_and_count(l, m); // 左半分を再帰的に数える
	long long cr = merge_and_count(m, r); // 右半分を再帰的に数える
	long long c = 0; // 左と右を混ぜるときの逆転数
	int i=l, j=m; // iは[l,m)を動き, jは[m,r)を動いて、
	int k=l; // 小さいものから W[k] に書き込む
	while (i<m && j<r) { // A[i]とA[j]を比べながら進む
		if (A[i] <= A[j]) W[k++] = A[i++]; // 左半分の方が小さく逆転なし
		else {
			W[k++] = A[j++];
			c += m-i; // 左半分の方が大きい、左半分で未処理の要素だけ飛び越える
		}
	}
	while (i<m) W[k++] = A[i++]; // 左半分が余った場合
	while (j<r) W[k++] = A[j++]; // 右半分が余った場合
	//assert(k == r);
	std::copy(W+l, W+r, A+l);
	return cl + cr + c;
}
int main(){
	int T,i,N;
	//PKU2299,aizu0167: バブルソートの交換回数
	//for(;scanf("%d",&N),N;printf("%lld\n",merge_and_count(0,N)))for(i=0;i<N;i++)scanf("%d",A+i);
	//hackerrank~runningtime
	scanf("%d",&N);for(i=0;i<N;i++)scanf("%d",A+i);printf("%lld\n",merge_and_count(0,N));
	//spojINVCNT,hackerrank~insertionsort
	//for(scanf("%d",&T);T--;printf("%lld\n",merge_and_count(0,N)))for(scanf("%d",&N),i=0;i<N;++i)scanf("%d",A+i);
	//codeiq432: 光線の交差数
	//for(N=0;~scanf("%d",A+N);N++);printf("%lld\n",merge_and_count(0,N));
	//codeiq838: あみだくじの最小本数
	//T=0,N=7;
	//std::vector<int>v(N);
	//std::iota(v.begin(),v.end(),1);
	//do{std::copy(v.begin(),v.end(),A);if(merge_and_count(0,N)==10)T++;}while(std::next_permutation(v.begin(),v.end()));
	//printf("%d\n",T); //573
	//kcs1009K: Nパズルの可解性
	//for(i=0;~(N=getchar());)if('0'<N&&N<'9')A[i++]=N-'0';
	//puts(merge_and_count(0,i)%2?"lmpossible":"Possible"); //"l"? lol!
}

Measured memory_bytes: 5916
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 500000
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 

ll dp[MAX];
ll f(ll* h,ll n,ll k){
	if(n==1) return 0;
	if(dp[n]!=-1) return dp[n];
	ll ans=1e15;
	For(i,1,min(n,k+1)){
		ll temp = f(h+i,n-i,k)+abs(h[0]-h[i]);
		ans = min(temp,ans);
	}
	// ll first = f(h+1,n-1)+abs(h[0]-h[1]);
	// ll second = f(h+2,n-2)+abs(h[0]-h[2]);
	dp[n]= ans;
	return dp[n];
}

int main(){
	ios_base::sync_with_stdio(false);
	memset(dp,-1,sizeof(dp));
	ll n,k;cin>>n>>k;
	ll h[n];For(i,0,n) cin>>h[i];
	cout<<f(h,n,k)<<endl;
}

Measured memory_bytes: 12800
#include<stdio.h>
#include<stdlib.h>

int *change(int *h,int a,int b) {

	int i,temp[50];

	for(i=0;i<a-1;i++)
		temp[i]=h[i];
	for(i=0;i<b;i++)
		h[i]=h[a-1+i];
	for(i=0;i<a-1;i++)
		h[b+i]=temp[i];
	return h;
}

int main() {

	int n,r;
	int i,j;
	int **c;
	int *h;
	int Answer[1000],a=0;

	for(;;) {
		scanf("%d %d",&n,&r);
		if(n==0&&r==0) break;
		c=malloc(r * sizeof(int *));
		for(i=0;i<r;i++)
			c[i]=malloc(2 * sizeof(int));

		for(i=0;i<r;i++)
			scanf("%d %d",&c[i][0],&c[i][1]);
		h=malloc(n * sizeof(int *));
		for(i=0;i<n;i++)
			h[i]=n-i;

		for(j=0;j<r;j++)
			change(h,c[j][0],c[j][1]);
		Answer[a]=h[0];
		a++;
		free(h),free(c);
	}
	for(i=0;i<a;i++)
		printf("%d\n",Answer[i]);
	return 0;
}

Measured memory_bytes: 700
#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5 + 5;
vector<int> gr[N];
ll d[N], used[N];
int cnt = 0;

void dfs(int v)
{
    used[v] = 1;
    int fl = 1;
    for(auto e : gr[v])
    {
        if(d[v] <= d[e])fl = 0;
    }
    if(fl)cnt++;
    for(auto e : gr[v])
    {
        if(!used[e])dfs(e);
    }
}
int main() {
    int n, m; cin >> n >> m;
    for(int i = 0; i < n; i++)cin >> d[i + 1];
    for(int i = 0; i < m; i++)
    {
        int u, v; cin >> u >> v;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    for(int i = 1; i <= n; i++)
    {
        if(!used[i])dfs(i);
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 11112