akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;

  vector<int> s(N,0);
  vector<int> sbit(N,0);
  vector<int> r(N,0);
  vector<int> rbit(N,0);

  int si=0,sbiti=0;
  int a=0,b=0;
  
  for(int i=0;i<N;i++){
    cin >> a;
    r[i]=si;
    rbit[i]=sbiti;
    si+=a;
    sbiti^=a;
    s[i]=si;
    sbit[i]=sbiti;
    //cout << i << "=" << bitset<21>(a) << endl;
  }

  a=0;
  ll ans=0;
  while(b<N){
    ans+=b-a+1;
    b++;
    while(a<b){
      if(s[b]-r[a]==(sbit[b]^rbit[a])) break;
      a++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a;
    set< int > st;
    for( int i = 0; i < 3; ++i ) {
        cin >> a;
        st.insert( a );
    }

    cout << st.size() << endl;

    return 0;
}



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

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

int x;
void ReadData() {
	cin >> x;
}

bool check(long long sum, int t) {
	sum -= x;
	sum /= 2;
	if (1LL * t * (t + 1) / 2 >= sum) return true;
	return false;
}

void Process() {
	if (x == 0) {
		cout << 0 << endl;
		return;
	}
	int t = 1;
	long long sum = 1;
	while (sum < x) {
		t++;
		sum += t;
	}
	if (sum == x) {
		cout << t << endl;
		return;
	}
	while (!check(sum,t)) {
		t++;
		sum += t;
	}

	cout << t << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}			

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define gcd __gcd
using namespace std;
signed main() {
  int n;
  cin>>n;
  int dp[n];
  vector<int>vec(n);
  rep(i,n) cin>>vec.at(i);
  dp[0]=0;
  dp[1]=abs(vec.at(1)-vec.at(0));
  for(int i=2;i<n;i++) {
    int a=abs(vec.at(i)-vec.at(i-1));
    int b=abs(vec.at(i)-vec.at(i-2));
    dp[i]=min(dp[i-1]+a,dp[i-2]+b);
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.lang.Integer;
public class Main {
	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String in  = br.readLine() ;
			String[] numStr = in.split(" ");
			int[] num = new int[4];
			num[0] = Integer.parseInt(numStr[0]);
			num[1] = Integer.parseInt(numStr[1]);
			if ( num[0] > num[1] ) {
				System.out.println( "a > b");
			} else if ( num[0] < num[1] ) {
				System.out.println( "a < b");
			} else {
				System.out.println( "a == b");
			}
		} catch ( IOException e ) {
			System.out.println("??¨??????????????????????????????");
		}
	}
}

Measured memory_bytes: 24248
'''
1 1 1
2 2 2
1
2
3
とあったら、1*1+1*2+1*3
          2*1+2*2+2*3
みたいな感じ。
'''

from operator import add
from functools import reduce

#テスト値
n,m = map(int,input().split())
#a = [[1,1,1],[2,2,2]]
#b = [1,2,3]

a = [list(map(int, input().split())) for n in range(n)]
#print(a)

b = [int(input()) for n in range(m)]
#print(b)

#ベクトル積の計算。
#まず行ごとの値を計算。
c = []
for n in range(n):
    c.append([a[n][m]*b[m] for m in range(m)])
    
#print(c)#ここまでOK。

d=[reduce(add,c[n]) for n in range(len(c))]



#print(d)

[print(d[i]) for i in range(len(d))]



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


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

    double a,b=0.0;

    for(int i =0; i < N; i++){
        cin >> a;
        b += (1.0 / a);
    }

    cout << 1.0 / b << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAXN=1e3+7;
const long long MOD=1e9+7;
int h,w,f[MAXN][MAXN];
char a[MAXN][MAXN];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0);
	cin>>h>>w;
	for(int i=1;i<=h;i++) cin>>(a[i]+1);
	f[0][1]=1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(a[i][j]!='#')
				f[i][j]=(f[i-1][j]+f[i][j-1])%MOD;
	cout<<f[h][w]<<endl;
	return 0;
}

Measured memory_bytes: 8468
# coding: utf-8
# Your code here
# coding: utf-8
# Your code here!

a =input()
N=list(a)
b=0
r=0
for i in N:
    if(i=="0"):
        b+=1
    else:
        r+=1
ans=r
if(r>b):
    ans=b
print(ans*2)






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

int N, W; long long D[100100];

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

	for (int j=1;j<=100000;j++) D[j] = 1e16;
	for (int i=1;i<=N;i++){
		int w,v; scanf ("%d %d",&w,&v);
		for (int j=100000-v;j>=0;j--) if (D[j+v] > D[j] + w) D[j+v] = D[j] + w;
	}
	for (int i=100000;i>=0;i--) if (D[i] <= W){
		printf ("%d\n",i);
		break;
	}

	return 0;
}


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

int main()
{
	int N;

	

	cin >> N;

	string result = "APPROVED";


	for (int a = 0; a < N; a++) {
		int A = 0;
		cin >> A;

		if (A % 2 == 0) {
			if (A % 3 != 0 && A % 5 != 0) {
				result = "DENIED";
				break;
			}

		}


	}
	
	cout << result<< endl;
}



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


int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  rep(i,N){
      cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  ll small=-1000000000000000010,big=1000000000000000010;
  while(big-small>1){
      ll count=0,m=(big+small)/2;
      for(ll i=0;i<N;i++){
          if(A.at(i)<0){
              ll num;
              if(m%A.at(i)==0){num=A.end()-lower_bound(A.begin(),A.end(),m/A.at(i));}
              else{
                  if(m>0){num=A.end()-lower_bound(A.begin(),A.end(),m/A.at(i));}
                  else{num=A.end()-lower_bound(A.begin(),A.end(),m/A.at(i)+1);}
              }
              
              if(num+i+1<=N){count+=num;}
              else{count+=N-i-1;}
          }
          if(A.at(i)==0){if(m>=0){count+=N-i-1;}}
          if(A.at(i)>0){
              ll num;
              if(m%A.at(i)==0){num=upper_bound(A.begin(),A.end(),m/A.at(i))-A.begin();}
              else{
                  if(m>0){num=upper_bound(A.begin(),A.end(),m/A.at(i))-A.begin();}
                  else{num=upper_bound(A.begin(),A.end(),m/A.at(i)-1)-A.begin();}
              }
              
              
              if(num>i+1){count+=num-i-1;}
          }
      }
      if(count<K){small=m;}
      else{big=m;}
  }
  cout<<big<<endl;
}

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

int main(void){
    int a=1;
    int b=1;

    cin >> a >> b;

    int ans=a*b;

    if(ans%2==0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }

    return 0;

}

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a,b,c,d,i,j,k,x=0,y=0;
    cin>>str;
    k=str.size();
    a=(k-1)/2;
    a--;
    b=(k+3)/2;
    b--;
    for(i=0,j=k-1; i<k/2; i++,j--)
    {
        if(str[i]!=str[j])
        {
            y=1;
            break;
        }
    }
    if(y==1)
        cout<<"No"<<endl;
    else
    {
        for(i=0,j=a; i<j; i++,j--)
        {
            if(str[i]!=str[j])
            {
                x=1;
                break;
            }
        }
        if(x==1)
            cout<<"No"<<endl;
        else
        {
            for(i=b,j=k-1; i<j; i++,j--)
            {
                if(str[i]!=str[j])
                {
                    x=1;
                    break;
                }
            }
            if(x==1)
                cout<<"No"<<endl;
            else
                cout<<"Yes"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	indexs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&indexs[i])
		indexs[i] -= 1 // 0 index
	}

	satisfactions := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&satisfactions[i])
	}

	bonus := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		fmt.Scan(&bonus[i])
	}

	score := satisfactions[indexs[0]]
	for i := 1; i < n; i++ {
		index := indexs[i]
		score += satisfactions[index]
		if index-indexs[i-1] == 1 {
			score += bonus[indexs[i-1]]
		}
	}

	fmt.Println(score)
}


Measured memory_bytes: 512
# 素因数分解(o√N)
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n = int(input())
d = {}
for i in range(1, n+1):
    for j in prime_factorize(i):
        if j not in d:
            d[j] = 1
        else:
            d[j] += 1
l = d.values()

ans = 0

 # (3,5,5)その１
a = 0
b = 0
for i in l:
    if 2 <= i <= 3:
        a += 1
for j in l:
    if 4 <= j:
        b += 1
ans += a*b*(b-1)/2

# (3,5,5)その２
a = 0
b = 0
for i in l:
    if 4 <= i:
        a += 1
ans += a*(a-1)*(a-2)/2

#(5,15)その１
a = 0
b = 0
for i in l:
    if 4 <= i <= 13:
        a += 1
for j in l:
    if 14 <= j:
        b += 1
ans += a*b

#(5,15)その２
a = 0
b = 0
for i in l:
    if 14 <= i:
        a += 1
ans += a*(a-1)

#(3,25)その１
a = 0
b = 0
for i in l:
    if 2 <= i <= 23:
        a += 1
for j in l:
    if 24 <= j:
        b += 1
ans += a*b

# (3,25)その２
a = 0
b = 0
for i in l:
    if 24 <= i:
        a += 1
ans += a*(a-1)

# (75)
a = 0
b = 0
for i in l:
    if 74 <= i:
        a += 1
ans += a

print(int(ans))

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(void) {
	int a, b, c, d, e;
	cin >> a >> b >> c;
	d = b + c;
	e = d - a;
	if (e <= 0)
		cout << "0" << endl;
	else
		cout << e << endl;
	return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<i32> = get_vec();
    let a : i32 = v[0];
    let b : i32 = v[1];
    let c : i32 = v[2];

    if b-a == c-b {
        println!("{}", "YES");
    }
    else {
        println!("{}", "NO");
    }

}


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

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<int>t(n), a(n);
	ll T, A; T = A = 1;
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> a[i];
		ll tmp = max(((T + t[i] - 1) / t[i]), ((A + a[i] - 1) / a[i]));
		T = t[i] * tmp, A = a[i] * tmp;
	}
	cout << T + A << endl;

	return 0;
}

Measured memory_bytes: 256
#オブジェクト指向忘れてた
#関数内は別物、参照作成なので
#def next_turn(s):
#    s0=s[0]
#    s=s[1:]
#    return s0

sa=input()
sb=input()
sc=input()

k=sa[0]
sa=sa[1:]
while True:
    #print(sa)
    #print(sb)
    #print(sc)
    if k=="a":
        if len(sa)==0:
            print("A")
            break
        else:
            k=sa[0]
            sa=sa[1:]
    elif k=="b":
        if len(sb)==0:
            print("B")
            break
        else:
            k=sb[0]
            sb=sb[1:]
    else:
        if len(sc)==0:
            print("C")
            break
        else:
            k=sc[0]
            sc=sc[1:]


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  string t, p;
  cin >> t >> p;

  const int len = (int)t.length();
  int begin = 0;

  for (;;) {

    const int found = t.find(p, begin);

    if (found != string::npos) {
      cout << found << LF;
      begin = found + 1;
    } else {
      break;
    }
  }

  return 0;
}




Measured memory_bytes: 3976
import collections

N=int(input())
S=sorted([input() for _ in range(N)])
s=sorted(list(set(S)))
l=len(s)
c=collections.Counter(S)
max_v = max(c.values())
for i in range(l):
    if max_v==c[s[i]]:
        print(s[i])

Measured memory_bytes: 175724
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;

int par[maxN], siz[maxN];

void init() {
	for (int i = 0; i < maxN; ++i) {
    	par[i] = i, siz[i] = 1; 
    }
}

int find(int x) {
	return par[x] == x ? x : par[x] = find(par[x]); 
}

bool same(int x, int y) {
	return find(x) == find(y);  
}

void unify(int x, int y) {
	x = find(x), y = find(y);
  	if (x == y) return;
  	if (siz[x] > siz[y]) {
    	siz[x] += siz[y];
      	par[y] = x;
    }
  	else {
    	siz[y] += siz[x];
      	par[x] = y;
    }
}

int main() {
	int n, q;
  	cin >> n >> q;
  	init();
  	for (int i = 0; i < q; ++i) {
    	int type, u, v;
      	cin >> type >> u >> v;
      	if (type) {
         	cout << same(u, v) << '\n';          
        }
      	else {
 			unify(u, v);
        }
    }
  	return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>A(N),B(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		B[i] = A[i];
	}
	sort(B.rbegin(), B.rend());

	for (int i = 0; i < N; i++)
	{
		if (A[i] == B[0]) {
			cout << B[1] << endl;
		}
		else {
			cout << B[0] << endl;
		}
	}
	return 0;
}

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

int main(){
	deque<int>v;
	int q;cin>>q;
	rep(i,q){
		int a,b;cin>>a>>b;
		if(a==0){
			int x;cin>>x;
			if(b==0)v.push_front(x);
			else v.push_back(x);
		}
		else if(a==1){
			cout<<v[b]<<endl;
		}
		else{
			if(b==0)v.pop_front();
			else v.pop_back();
		}
	}
}


Measured memory_bytes: 4664
import java.util.*;
import java.io.*;
public class Main {
	public String simulate(char[] x, char[] y, char[] a){
		if( a.length < Math.max(x.length, y.length) ){
			return "NA";
		} 
outer:	for(int i = 0; i <= 9; i++){
			if( i == 0 ){
				if( (x.length > 1 && x[0] == 'X') || (y.length > 1 && y[0] == 'X') || (a.length > 1 && a[0] == 'X') ){
					continue;
				}
			}
			int add = 0;
			for(int j = 1; j <= a.length; j++){
				int p = (x.length-j < 0) ? 0 : (x[x.length-j] == 'X') ? i : x[x.length-j]-'0';
				int q = (y.length-j < 0) ? 0 : (y[y.length-j] == 'X') ? i : y[y.length-j]-'0';
				int r = (a[a.length-j] == 'X') ? i : a[a.length-j]-'0';
		//		System.out.println(p + " " + q + " " + r);
				int sum = p+q+add;
				if( sum%10 == r ){
					add = sum/10;
					continue;
				} else {
					continue outer;
				}
			}
			return Integer.toString(i);
		}
		return "NA";
	}
			
    public void solve() throws IOException{
    	Scanner stdIn = null;
    	try{
    		stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        	while( stdIn.hasNext() ){
            	String str = stdIn.next();
            	String[] s = str.split("=");
           	   	String[] t = s[0].split("\\+");
               	char[] x = t[0].toCharArray();
            	char[] y = t[1].toCharArray();
            	char[] a = s[1].toCharArray();
            	System.out.println(simulate(x, y, a));
       		}
       	} finally {
       		if( stdIn != null ){
       			stdIn.close();
       		}
       	}
    }
    public static void main (String args[]) throws IOException{
        new Main().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer; 
    public void run() throws IOException{
        try{
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e){
            e.printStackTrace();
            System.exit(1);
        }
    }
    public int nextInt() throws IOException{
        return Integer.parseInt(nextToken());
    }
    public String nextToken() throws IOException{
        while( tokenizer == null || !tokenizer.hasMoreTokens() ){
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
} 

Measured memory_bytes: 12000
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct edge{ll to, sum;};
const int N = 1e5 + 10;
ll n, m, u[N], v[N], s[N], c[N], visit[N], bi[N];
vector<edge> e[N];
VL ru, rv, rs;

void dfs(int now){
    for (edge eg : e[now]){
        int next = eg.to;
        if (visit[next]){
            if (bi[now] == bi[next]){
                ru.push_back(now);
                rv.push_back(next);
                rs.push_back(eg.sum);
            }
            continue;
        }
        visit[next] = 1;
        bi[next] = (bi[now] ^ 1);
        c[next] = eg.sum - c[now];
        dfs(next);
    }
}

bool check(){
    REP(i,n) if (c[i] < 1) return false;
    REP(i,m){
        if (c[u[i]] + c[v[i]] != s[i]) return false;
    }
    return true;
}

int main() {
    cin >> n >> m;
    REP(i,m){
        u[i] = in() - 1;
        v[i] = in() - 1;
        s[i] = in();
        e[u[i]].push_back((edge){v[i], s[i]});
        e[v[i]].push_back((edge){u[i], s[i]});
    }

    c[0] = 1;
    visit[0] = 1;
    dfs(0);

    if (!ru.empty()){
        ll d = rs[0] - c[ru[0]] - c[rv[0]];
        if (abs(d) % 2 != 0){
            cout << 0 << endl;
            return 0;
        }
        d /= 2;
        REP(i,n){
            if (bi[i] == bi[ru[0]]) c[i] += d;
            else c[i] -= d;
        }
        cout << (int)check() << endl;
        return 0;
    }

    VL mi(2, 1e18);
    REP(i,n){
        mi[bi[i]] = min(mi[bi[i]], c[i]);
    }
    if (mi[0] < 1){
        REP(i,n){
            if (bi[i] == 0) c[i] += 1 - mi[0];
            else c[i] -= 1 - mi[0];
        }
    }

    ll ans = max(0LL, mi[0] + mi[1] - 1);
    if (!check()) ans = 0;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20352
s = list(input())
ans = 0
tmp = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    
    int half = n / 2;
    
    if(n % 2 == 0){
        if(half >= k) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    
    if(n % 2 == 1){
        if(half + 1 >= k) cout << "YES"  << endl;
        else cout << "NO" << endl;
    }
    
    return 0;
}

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

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

int main(){
  int N;
  int list[300001] = {0};
  priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
  priority_queue<long long int> PQ1;

  long long int zenhanSum = 0;
  long long int kouhanSum = 0;

  long long int zenhanlist[100001] = {0};
  long long int kouhanlist[100001] = {0};

  cin >>N;

  for(int i = 0;i<3*N;i++){
      cin >>list[i];
      if(i < N){
          PQ.push(list[i]);
          zenhanSum+=list[i];
    }
        if(2*N<=i){
            PQ1.push(list[i]);
            kouhanSum+=list[i];
            }
  }
  
  zenhanlist[0] = zenhanSum;
  kouhanlist[0] = kouhanSum;

  long int ans = zenhanSum-kouhanSum;

  for(int k = N;k < 2*N;k++){
      if(PQ.top() < list[k]){
          zenhanSum -= PQ.top();
          PQ.pop();
          PQ.push(list[k]);
          zenhanSum += list[k];

      }
      zenhanlist[k-N+1] = zenhanSum;

      if(PQ1.top() > list[3*N-1-k]){
          kouhanSum -= PQ1.top();
          PQ1.pop();
          PQ1.push(list[3*N-1-k]);
          kouhanSum += list[3*N-1-k];
      }
      kouhanlist[k-N+1] = kouhanSum;
  }

  for(int i = 0;i<=N;i++){
      if(ans < zenhanlist[i]-kouhanlist[(N)-i])ans = zenhanlist[i]-kouhanlist[(N)-i];
  }
  cout <<ans<<endl;

  return 0;
}

Measured memory_bytes: 5236
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    int left, right;
    right = n % 100;
    left = n / 100;
    if ((left > 12 && right > 12) || (left == 0 && right == 0) || (left > 12 && right == 0) || (right > 12 && left == 0)) {
      cout << "NA" << '\n';
    } else if (left > 0 && left < 13 && right > 0 && right < 13) {
      cout << "AMBIGUOUS" << '\n';
    } else if (left > 0 && left < 13 && (right < 1 || right > 12)) {
      cout << "MMYY" << '\n';
    } else {
      cout << "YYMM" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
def bellman_ford(vertexes, edges, costs, start):
    # cost to each vertex
    d = [float("inf")] * vertexes
    # start cost is zero
    d[start] = 0
    for i in range(vertexes):
        update = False
        for j in range(len(edges)):
            frm, to = edges[j]
            cost = costs[j]
            if d[to] > d[frm] + cost:
                d[to] = d[frm] + cost
                update = True
        # stop if not updated
        if not update:
            break

        # find if closed-loop exists
        if i == n - 1:
            return -1

    return d


n, m, s = map(int, input().split())

edges = []
costs = [-float("inf")] * (m)
score = [-float("inf")] * (n + 1)

for i in range(m):
    a, b, c = map(int, input().split())
    edges.append([a, b])
    costs[i] = c

d = bellman_ford(n, edges, costs, s)

if d == -1:
    print("NEGATIVE CYCLE")
else:
    for i in range(n):
        print(d[i]) if d[i] != float("inf") else print("INF")



Measured memory_bytes: 6164
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] s = new int[N];
		int sum = 0;
		for(int i=0; i<N; i++) {
			s[i] = sc.nextInt();
			sum += s[i];
		}
		Arrays.sort(s);
		if(sum%10 != 0) {
			System.out.println(sum);
		} else {
			int min = sum;
			for(int i=N-1; i>=0; i--) {
				if(s[i]%10 != 0)
					min = s[i];
			}
			System.out.println(sum-min);
		}
		sc.close();
	}
}


Measured memory_bytes: 23636
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
using vll = vector<long long>;

int main(){
    long N;
    cin>>N;
    long t[N+1];
    long x[N+1];
    long y[N+1];
    t[0]=x[0]=y[0]=0;
    for(auto i=1;i<=N;i++)cin>>t[i]>>x[i]>>y[i];
    bool flag = true;
    for(auto i=1;i<=N;i++){
        long dist = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
        if(dist>t[i]-t[i-1])flag=false;
        else if((t[i]-t[i-1]-dist)%2==1)flag = false;
    }
    cout<<(flag?"Yes":"No")<<endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long 
# define pb push_back 

void solve() {
	int h, w , k ; 
	cin >> h >> w >> k ; 
	int ans = 0 ; 
	char a[h][w] ; 
	for(int i = 0; i < h ; ++i) {
		for(int j = 0 ; j < w ; ++j)
			cin >> a[i][j]; 
	}
	for(int i = 0; i < (1<<h) ; ++i) {
		for(int j = 0 ; j < (1<<w) ; ++j) {
			int black= 0 ; 
			for(int i2 = 0 ; i2 < h ; ++i2) {
				for(int j2 = 0 ; j2 < w ; ++j2) {
					if(((i >> i2) & 1) == 0 && ((j >> j2) & 1) == 0 && a[i2][j2] == '#')
						black++;
				}
			}
			if(black == k) 
				ans ++ ; 
		}
	}
	cout << ans ; 
}

int main()
{
	int t ; 
	//cin >> t; 
	t =1 ; 
	while(t--) {
		solve() ; 
	}
	return 0 ; 
} 

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

typedef struct{
    char type;
    int num;
}card;

bool isStable(const card in[], const card out[], int N){
    for(int i=0;i<N;++i)
        for(int j=i+1;j<N;++j)
            for(int a=0;a<N;++a)
                for(int b=a+1;b<N;++b)
                    if(in[i].num==in[j].num &&
                       in[i].type==out[b].type && in[i].num==out[b].num &&
                       in[j].type==out[a].type && in[j].num==out[a].num)
                        return false;
    return true;
}

void printArray(const card in[], int n){
    for(int i=0;i<n;++i)
    {
        if(i)
            cout<<" ";
        cout<<in[i].type<<in[i].num;
    }
}

void swapCard(card *a, card *b){
    char ch=a->type;
    int temp=a->num;

    a->type=b->type;
    a->num=b->num;

    b->type=ch;
    b->num=temp;
}

int main()
{


    int n;
    cin>>n;

    card a[36];
    card in[36];
    card b[36];
    for(int i=0;i<n;++i)
    {
        cin>>a[i].type>>a[i].num;
        b[i].type=in[i].type=a[i].type;
        b[i].num=in[i].num=a[i].num;
    }

    //bubble sort
    bool flag=1;
    for(int i=0;flag;++i)
    {
        flag=0;
        for(int j=n-1;j>i;--j)
        {
            if(a[j].num < a[j-1].num)
            {
                swapCard(&a[j], &a[j-1]);
                flag=1;
            }
        }
    }

    printArray(a,n);

    if(isStable(in, a, n))
        cout<<endl<<"Stable"<<endl;
    else
        cout<<endl<<"Not stable"<<endl;

    //selection sort
    for(int i=0;i<n;++i)
    {
        int min=i;
        for(int j=i;j<n;++j)
        {
            if(b[j].num<b[min].num)
                min=j;
        }
        if(min!=i)
        {
            swapCard(&b[i], &b[min]);
            flag=1;
        }
    }

    printArray(b,n);

    if(isStable(in, b, n))
        cout<<endl<<"Stable"<<endl;
    else
        cout<<endl<<"Not stable"<<endl;


    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6, mod = 1e9 + 7;
int N, M, K, L, R;
long long ans, last;
long long fac[maxn], inv[maxn], p[maxn];

inline long long fpow(long long t, int x){
    long long ret = 1, tmp = t;
    while(x){
        if(x & 1) ret = ret * tmp % mod;
        tmp = tmp * tmp % mod; x >>= 1;
    }
    return ret;
}

inline void prepare(){
    fac[0] = 1; inv[0] = 1; p[0] = 1;
    for(int i = 1; i <= N + M + K; ++i) fac[i] = fac[i - 1] * i % mod, p[i] = p[i - 1] * 3 % mod;
    inv[N + M + K] = fpow(fac[N + M + K], mod - 2);
    for(int i = N + M + K - 1; i >= 1; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}

inline long long C(int n, int m){
    if(m > n) return 0;
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

inline long long calc(int l, int r, int x){
    long long ret = last;
    ret = last * 2 - C(x - 1, L) - C(x - 1, R) + C(x, L);
    while(R < r){R++; ret += C(x, R);}
    while(L < l){L++; ret -= C(x, L - 1);}
    while(ret < 0) ret += mod; last = ret % mod;
	return last;
}



inline void workk(){
    for(int len = N - 1; len < N + M + K; ++len){
        long long ret = p[N + M + K - len - 1] * C(len, N - 1) % mod;
        if(len == N - 1){last = 1; ans = ret * last % mod;}
        else ans = (ans + ret * calc(max(0, len - (N - 1) - K), min(M, len - (N - 1)), len - (N - 1))) % mod;
    }
    cout << ans;
}

int main()
{
    scanf("%d%d%d", &N, &M, &K);
    prepare();
    workk();
    return 0;
}

Measured memory_bytes: 22912
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <cstdio>
using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define SINV(t) greater<t>()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP2(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
#define vv(t) vector<t>

template<typename T>
void SV(vector<T> v){
    REP(i,v.size()){
        #ifdef LOCAL
            cout << i << " : " << v[i] << endl;
        #endif
    }
}

int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}


int main(){
    int K;
    cin >> K;
    ll n = 1;
    vv(int) s(10);
    s[0] = 1;
    REP(i, K){
        ll tn = n;
        ll ehig = 1;
        /*
        while(tn/10){
            cout << "!"<< tn%10 << (tn/10)%10 << endl;
            if(abs(tn%10-(tn/10)%10) > 1){

            }
        }*/
        tn = 0;
        ll sss=10;
        for(int j=1; j<10 && (n/sss || s[j-1] > 9); j++, sss*=10){
            if(s[j-1] > 9){
                s[j]++;
                s[j-1] = 0;
                tn = j;
            }else if(abs(s[j]-s[j-1]) > 1){
                s[j]++;
                n+=sss;
                tn = j;
            }else {
                break;
            }
        }
        //cout << tn << endl;
        for(int j=tn, cnt=s[tn]; j>=0; j--, cnt--){
            if(cnt<0)
                cnt=0;
            s[j] = cnt;
        }
        //if(i > 50)
        //cout << "--------"<< n << endl;
        n=0;
        sss = 1;
        for(int j=0;j<10;j++){
            n+=sss*s[j];
            sss*=10;
        }
        s[0]++;
        //cout << n << endl;
    }
    cout << n << endl;
    //    cout << s[0]+s[1]*10+s[2]*100+s[3]*1000*s[4]*10000 << endl;;
}


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

{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s1,s2;
	cin >> s1>> s2;
	int count=0;
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]!=s2[i])
		
		{
			count++;
		}
	}
	cout << count ;
}

Measured memory_bytes: 3912
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

#define MAX 10000

struct Node {int parent, left, right;};

Node T[MAX];
int n,D[MAX],H[MAX];

void setdepth(int u, int d){
	if(u==-1)
	return;
	D[u]=d;
	setdepth(T[u].left, d+1);
	setdepth(T[u].right, d+1);
}

int setheight(int u){
	int h1=0,h2=0;
	if(T[u].left!=-1)
	h1=setheight(T[u].left)+1;
	if(T[u].right!=-1)
	h2=setheight(T[u].right)+1;
	return H[u] = (h1>h2 ? h1:h2);
}

int getsibling(int u){
	if(T[u].parent==-1)
	return -1;
	if(T[T[u].parent].left!=u && T[T[u].parent].left!=-1)
	return T[T[u].parent].left;
	if(T[T[u].parent].right!=u && T[T[u].parent].right!=-1)
	return T[T[u].parent].right;
	return -1;
}

void print(int u){
	int deg;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getsibling(u));
	if(T[u].left!=-1) deg++;
	if(T[u].right!=-1) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent==-1)
	printf("root\n");
	else if(T[u].left==-1 && T[u].right==-1)
	printf("leaf\n");
	else
	printf("internal node\n");
}

int main(){
	int n,id,l,r,root=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		T[i].parent=-1;
	}
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&id,&l,&r);
		T[id].left=l;
		T[id].right=r;
		if(l!=-1)
		T[l].parent=id;
		if(r!=-1)
		T[r].parent=id;
	}
	for(int i=0;i<n;i++){
		if(T[i].parent==-1)
		root=i;
	}
	setdepth(root,0);
	setheight(root);
	for(int i=0;i<n;i++){
		print(i);
	}
}

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

const int INF = 1e9;

struct s {
	int cost;
	int same;
	s() {cost = -1; same = -1;}
	s(int cost_, int same_) {
		cost = cost_; same = same_;
	}
	bool operator<(const s & obj) const {
		return this->cost < obj.cost;
	}
};

int N;
vector<int> t;
int dptab[20][10010][2];

int dp(int b, int e, int m, int back, int depth) {
	if(m == 0 && back == 1)
		return 0;
	else if(e-b == m && back == 0)
		return 0;
	else if(m == 0 || e-b == m)
		return INF;

	if(dptab[depth][b+m][back] + 1)
		return dptab[depth][b+m][back];

	int le, ri, mi;
	le = b;
	ri = e;
	mi = (b+e)/2;

	dptab[depth][b+m][back] = INF;
	for(int i = max(1, m-(ri-mi)); i <= min(mi-le, m); i++) {
		int res[4] = {0};
		int cost0, cost1, cost2, cost3;

		res[0] = dp(le, mi,             i,     0, depth+1);
		res[1] = dp(le, mi,             i,     1, depth+1);
		res[2] = dp(mi, ri,           m-i,  back, depth+1);
		res[3] = dp(mi, ri, (ri-mi)-(m-i), !back, depth+1);

		for(int j = 0; j < 4; j++) {
			int indx0, indx1;
			indx0 = j&1; indx1 = (j&2)>>1;
			dptab[depth][b+m][back] = min(dptab[depth][b+m][back], res[indx0] + res[indx1|2] + ((indx0^indx1^(indx1 ? !((ri-mi)-(m-i)) : !(m-i))) ? t[mi-1] : 0));
		}
	}
	return dptab[depth][b+m][back];
}

int main() {
	cin >> N;
	for(int i = 0; i < N-1; i++) {
		int tmp;
		cin >> tmp; t.push_back(tmp);
	}
	for(int i = 0; i < 20; i++) {
		for(int j = 0; j< 10010; j++) {
			dptab[i][j][0] = dptab[i][j][1] = -1;
		}
	}
	cout << min(dp(0,N,N/2,0,0), dp(0,N,N/2,1,0)) << endl;
}

Measured memory_bytes: 2884
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    ll ma[2][3], mi[2][3];
    rep(i, 2)rep(j, 3) {
        ma[i][j] = LLONG_MIN / 3;
        mi[i][j] = LLONG_MAX / 3;
    }

    auto put = [&](int i, int j, ll z) {
        smax(ma[i][j], z);
        smin(mi[i][j], z);
    };

    int N;
    cin >> N;
    rep(i, N) {
        ll x, y;
        char c;
        cin >> x >> y >> c;
        x *= 2;
        y *= 2;
        if (c == 'R') {
            put(0, 0, x);
            put(1, 2, y);
        } else if (c == 'L') {
            put(0, 1, x);
            put(1, 2, y);
        } else if (c == 'U') {
            put(0, 2, x);
            put(1, 0, y);
        } else {
            put(0, 2, x);
            put(1, 1, y);
        }
    }

    ll ans = LLONG_MAX;
    rep(t, 100000001) {
        static ll A[2];
        rep(i, 2) {
            ll large = max({ ma[i][0] + t, ma[i][1] - t, ma[i][2] });
            ll small = min({ mi[i][0] + t, mi[i][1] - t, mi[i][2] });
            A[i] = large - small;
        }
        smin(ans, A[0] * A[1]);
    }
    
    cout << ans / 4.0 << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
                using namespace std;
                #define lli long long int
                #define fr(i,a,b) for(int i=a;i<b;i++)
                #define bfr(i,a,b) for(int i=a;i>=b;i--)
                #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
                #define tc int t;cin>>t;while(t--)
                #define mod 1000000007 
                #define all(vec) vec.begin(),vec.end()  
                #define ld long double


                   

               
        int main()
                {
                       
                       
                    
                     fio


                     lli a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
                     lli x;
                     cin>>x;
                     cout<<a[x-1];



                     


                     



                     

                     

                     

                     





                     


                     







                     


                     

                     

                     


return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   ll x,k,d;
   cin>>x>>k>>d;
   
   ll ans = LLONG_MAX;
   ans = min({ans,abs(x+k*d),abs(x-k*d)});
   ll req = abs(x)/d;
   for(ll i=req-100;i<=req+100;i++)
   {
       if(i>=0 && i%2 == k%2 && i<=k)
       {
            ans = min({ans,abs(x+i*d),abs(x-i*d)});
       }
   }
   
   cout<<ans;
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	int a, b, c;
	cin >> a;
	int x, y;
	x = a % 10;
	a /= 10;
	y = a % 10;
	a /= 10;
	if (a == x){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

typedef struct edge{
	int u,v;
} EDGE;

int search(int n,int visited[],int node[n][n],int position){
	int node_local[n][n];
	int visited_local[n];
	memcpy(node_local,node,sizeof(int)*n*n);
	memcpy(visited_local,visited,sizeof(int)*n);
	int i,j;
	int sum=0;
	visited_local[position]=1;
	
	/* puts("==========");
	printf("node:%d\n",position+1);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			printf("%d",node_local[i][j]);
		}puts("");
	}
	printf("visited node\n");
	for(i=0;i<n;i++){
		printf("%d",visited_local[i]);
	}puts("");
	puts("=========="); */
	
	visited_local[position]=1;
	for(i=0;i<n;i++){
		if(node_local[position][i]==1){
			node_local[position][i]=0;
			if(visited_local[i]==0){
				sum+=search(n,visited_local,node_local,i);
			}
		}
	}
	
	int allVisited=1;
	for(i=0;i<n;i++){
		if(visited_local[i]==0){
			allVisited=0;
			break;
		}
	}
	
	return sum+allVisited;
}

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	EDGE e[m];
	int node[n][n];
	int visited[n];
	int i,j;
	for(i=0;i<n;i++){
		visited[i]=0;
		for(j=0;j<n;j++){
			node[i][j]=0;
		}
	}
	
	for(i=0;i<m;i++){
		scanf("%d %d",&e[i].u,&e[i].v);
		e[i].u--;e[i].v--;
		node[e[i].u][e[i].v]=1;
		node[e[i].v][e[i].u]=1;
	}
	
	int position=0;
	printf("%d\n",search(n,visited,node,position));
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int flag,i,j,c,count=0,N,A[100];

  flag = 1;

  scanf("%d",&N);

  if(N < 1 || N > 100) return 0;

  for( i = 0 ; i < N ; i++ )
    {
      scanf("%d",&A[i]);
    }
  
  while(flag)
    {
      flag = 0;
      for( j = N-1 ; j >= 1  ; j--)
	{
	  if(A[j] < A[j-1])
	    {
	      c = A[j];
	      A[j] = A[j-1];
	      A[j-1] = c;
	      flag = 1;
	      count++;
	    }
	}
    }

  for( i = 0 ; i < N ; i++ )
    {
      printf("%d",A[i]);
      if(i < N-1) printf(" ");
    }
  printf("\n");

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

  return 0;
}



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

int main() {
   int x;
   cin >> x;
   if (x == 1) cout << 0 << endl;
   if (x == 0) cout << 1 << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
vector<pair<int,int>> tasks;
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  
  int N; 
  cin >> N;
  
  for(int i=0; i<N; i++){
    int a,b;
    cin >> a >> b;
    tasks.emplace_back(b,a);
  }
  
  sort(tasks.begin(),tasks.end());
  int sum =0;
  bool kekka =true;
  
  for(auto v:tasks){
    sum += v.second;
    if(sum>v.first){
      kekka =false;
      break;
    } 
  }
  
  cout <<  (kekka? "Yes" : "No") << '\n';
}

Measured memory_bytes: 2420
n = int(input())
h = list(map(int,input().split()))
 
now = 0
count = 0
ans = 0
 
for i in h:
    if now >= i:
        count += 1
    else:
        ans = max(ans,count)
        count = 0
    now = i
 
print(max(ans,count))

Measured memory_bytes: 14252
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    ll N; cin >> N;

    ll ans = 0;
    
    for (int i = 1; true; i++) {
        if ((i*N)%2==0){
            ans = i * N;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e7;
const int inf=1e9;
int main(){
	int X;cin>>X;
	int ans = (X/500)*1000 + (X%500)/5*5;
	cout<<ans<<endl;
}

Measured memory_bytes: 256