akhauriyash/Code-Regression huggingface dataset:
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        String[] words;
        int[] count = new int[4];

        for(int i = 0; i < 3; i++)
        {
            line = Console.ReadLine();
            words = line.Split(' ');
            count[int.Parse(words[0])-1]++;
            count[int.Parse(words[1])-1]++;
        }
        int count1 = 0;
        int count2 = 0;
        for(int i = 0; i < 4; i++)
        {
            if (count[i] == 1)
            {
                count1++;
            }
            if (count[i] == 2)
            {
                count2++;
            }
        }
        if (count1 == 2 && count2 == 2)
            Console.WriteLine("YES");
        else
            Console.WriteLine("NO");
    }
}

Measured memory_bytes: 13140
#include<cstdio>
int num[37],cunt=0;
void S(int n)
{
    int ans=0;
    for(int i=0; i<=9; i++)
    {
        if(i>n)
            break;
        for(int k=0; k<=9; k++)
        {
            if(k>n)
                break;
            for(int j=0; j<=9; j++)
            {
                if(j>n)
                    break;
                for(int m=0; m<=9; m++)
                {
                    if(i+k+j+m==n)
                        ans++;
                    if(m>n)
                        break;
                }
            }
        }
    }
    num[cunt++]=ans;
    return ;
}
int main()
{
    for(int i=0; i<=36; i++)
        S(i);
    int n;
    while(~scanf("%d",&n))
    {
        if(n>=0&&n<=36)
            printf("%d\n",num[n]);
        else
            printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int x;
	cin >> x;
	int a = x % 100;
	int b = (x - a) / 100;
	rep(i, 0, 1000) {
		if ( a+100*i <= 5 * (b-i)) {
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}


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

int main() {
    int N,M;//Nheya Mhon
    cin >> N >> M;
    vector<vector<int>> Graph(N+1);
    
    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        Graph.at(a).push_back(b);
        Graph[b].push_back(a);
    }
    
    vector<int> dist(N+1,-1); //全頂点を未訪問に
    queue<int> que;
    vector<int> map(N+1,-1);
    
    dist[1]=0;
    que.push(1);
    
    while(!que.empty()){
        int v = que.front();
        que.pop();
        
        //vから辿れるすべてを
        for(int nv : Graph[v]){
            if(dist[nv] != -1) continue; //探索済みはみない
            
            //新たな白色頂点nvについて距離情報を更新してキューについか
            dist[nv] = dist[v] + 1;
            que.push(nv);
            map[nv] = v;
        }
    }
    
    bool flag=true;
    for(int i=2; i<=N; i++){
        if(dist[i]==-1) flag=false;
        //cout << dist[i] << endl;
    }
    
    if(flag){
        cout << "Yes" << endl;
        for(int i=2; i<=N; i++){
            cout << map[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }
   
}


Measured memory_bytes: 10660
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int &a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,t,a; cin >> n >> t >> a;
    int ans = 0 , cc = INF;
    FOR(i,1,n+1){
        int h; cin >> h;
        int d = (t*1000-h*6)-a*1000;
        if(cc>ABS(d)){cc = d; ans = i;}
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
a, b = map(int, input().split())
if a % 2 == 1 and b % 2 == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 5052
n,m=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(n)]
food=L[0][1:]
good=[]
for i in range(1,n):
    for j in range(len(food)):
        if food[j] in L[i][1:]:
            good.append(food[j]) 
    food = good
    good=[]
print(len(food))

Measured memory_bytes: 3064
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  N %= 10;

  if (N == 3)
    cout << "bon" << endl;
  else if (N == 0 || N == 1 || N == 6 || N == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
	cin >> n;
	
	while(n--)
	{
		string line;
		cin >> line;
		
		vint train(100, 0);
		
		
		int now = 50;
		train[now] = line[0];
		
		
		rep(i, line.size() / 3)
		{
			now += (line[i * 3 + 2] == '>' ? 1 : -1);
			
			if(!train[now])
				train[now] = line[i * 3 + 3];
		}
		
		
		for(int i = 1; !(train[i - 1] != 0 && train[i] == 0); i++)
		{
			if(train[i] != 0) cout << (char)train[i];
		}
		
		cout << endl;
	}
}

Measured memory_bytes: 0
N, K = map(int, input().split())
A = list(map(int, input().split()))
s = []
d = [-1] * (N + 1)
v = 1
c, l = 1, 0
while d[v] == -1:
    d[v] = len(s)
    s.append(v)
    v = A[v - 1]
c = len(s) - d[v]
l = d[v]
if K < l:
    print(s[K])
else:
    K -= l
    K %= c
    print(s[l + K])

Measured memory_bytes: 32356
#include<iostream>
#include<math.h>
using namespace std;


int main() {
	long long num;
	long long fac[10000][2] = { 0 };
	int count = 0;
	long long i;
	cin >> num;
	
	long long num2 = sqrt(num) + 1;

	for (i = 2; i <= num2; i++ ) {
		if (num % i == 0) {
			fac[count][0] = i;
			fac[count][1] = 0;
			while (num % i == 0) {
				fac[count][1]++;
				num /= i;
			}
			count++;
		}
	}

	if (num > num2) {
		fac[count][0] = num;
		fac[count][1] = 1;
		count++;
	}

	//for (i = 0; i < count;i++) cout << fac[i][0] << '&' << fac[i][1] << endl;
	
	int div = 0;
	for (i = 0; i < count; i++) {
		int a = 0;
		for (int k = 0; k <= fac[i][1]; k++) {
			a += k;
			if (a == fac[i][1]) {
				div += k;
				break;
			}
			else if (a > fac[i][1]) {
				div += k - 1;
				break;
			}
		}
	}

	cout << div << endl;

	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 50) - 1;
int MOD = 1e9+7;
main(){
    ll N,X;
    cin >> N >> X;
    vector<ll> V(N),minV(N);
    rep(i,0,N){
        cin >> V[i];
        minV[i] = V[i];
    }
    ll mini = INF;
    rep(i,0,N){
        ll sum = i * X;
        rep(j,0,N){
            minV[j] = min(minV[j], V[(j-i+N)%N]);
            sum += minV[j];
        }
        mini = min(mini, sum);
    }
    cout << mini << endl;
}

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

namespace abc199_a
{
    public class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split('/');
            int Y = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            int D = int.Parse(input[2]);

            Console.WriteLine(Seileki(Y,M,D));

        }

        public static string Seileki(int y, int m, int d)
        {
            if (y <= 2019 && m <= 4 && d <= 30)
            {
                return "Heisei";
            }
            else
            {
                return "TBD";
            }

        }



    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#include <algorithm> // sort
#include <map>
using namespace std;

int main(){
    int m,d;
    cin>>m>>d;
    int c;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            if(j/10>1&&j%10>1&&(j/10)*(j%10)==i){
                c++;
            }
        }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
void IO(){typedef int MyCustomType;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    //freopen("output.txt", "w", stdout);
	#endif
}
// end of Template
str s;
bool valid=false;
int f;
int main(){

	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>s;
 
    for(int i=2;i<s.size()-1;i++){
    	if(s[i]=='C')valid=true;
    }
    if(s[0]!='A')valid=false;
    for(int i=0;i<s.size();i++){
    	if(65<=int(s[i]) && int(s[i])<=90)f++;
    }
    if(f!=2)valid=false;

    if(valid)cout<<"AC\n";
    else cout<<"WA\n";

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, tmp, ans , MXN = 1<<30 -1;
vector<int> v;
int main(){
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>tmp;
        v.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
        if(MXN >= v[i]){
            MXN = v[i];
            ans++;
        }
    }
    cout<<ans;
}

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

struct city {
    int i;
    int p;
    int y;
    int order_in_pref;
};

bool asc_py(const city& a, const city& b) {
    return a.p == b.p ? a.y < b.y : a.p < b.p;
}

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

    city c[m];
    for (int i = 0; i < m; i++) {
        c[i].i = i;
        cin >> c[i].p >> c[i].y;
    }
    sort(c, c + m, asc_py);

    int before_p = 0;
    int order_in_pref;

    for (int i = 0; i < m; i++) {
        if (before_p != c[i].p) {
            before_p = c[i].p;
            order_in_pref = 1;
        }
        c[i].order_in_pref = order_in_pref++;
    }

    sort(c, c + m, [](city a, city b){ return a.i < b.i; });

    for (int i = 0; i < m; i++) {
        cout << setw(6) << setfill('0') << c[i].p;
        cout << setw(6) << setfill('0') << c[i].order_in_pref << endl;
    }

    return 0;
}


Measured memory_bytes: 3072
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	vector<int> a(200001,0);
	int n, k;
	cin >> n >> k;
	ll sum = 0;
	REP(i, n) {
		int x;
		cin >> x;
		a[x]++;
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	REP(i, k) {
		sum += a[i];
	}
	cout << n - sum << endl;
}



Measured memory_bytes: 1024
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if max(p[i-1],p[i],p[i+1])!=p[i] and min(p[i-1],p[i],p[i+1])!=p[i]:
    ans+=1
print(ans)

Measured memory_bytes: 9136
//Deep Godhani
//DAIICT

#include<bits/stdc++.h>
using namespace std;

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x,d) cout << fixed << setprecision(d) << x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

void dfs(ll curr,vector<vector<ll>> &v,vector<bool> &vis, int &count)
{
  vis[curr] = true;
  count++;

  for(int i=0;i<(int)v[curr].size();i++)
  {
    if(!vis[v[curr][i]])
    {
      dfs(v[curr][i],v,vis,count);
    }
  }
}

void solve()
{
  ll n,m;
  cin >> n >> m;

  vector<vector<ll>> v(n+1);
  set<pair<ll,ll>> s;
  for(int i=0;i<m;i++)
  {
    int x,y;
    cin >> x >> y;
    if(s.find({x,y}) != s.end())
    {
      continue;
    }
    s.insert({x,y});
    v[x].push_back(y);
    v[y].push_back(x);
  }

  vector<bool> vis(n+1,false);
  int ans = 0,count = 0;
  for(int i=1;i<=n;i++)
  {
    if(!vis[i])
    {
      count = 0;
      dfs(i,v,vis,count);
      ans = max(ans, count);
    }
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 39020
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

char solve(map<char, string>& mp) {
  char target = 'a';
  while (true) {
    if (mp[target].empty()) {
      break;
    } else {
      char next_target = *(mp[target].end() - 1);
      mp[target].pop_back();
      target = next_target;
    }
  }
  return toupper(target);
}

int main() {
  map<char, string> mp;
  REP(i, 3) {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    mp.insert(make_pair('a' + i, s));
  }
  cout << solve(mp) << endl;
}


Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

k,x = I()
print("Yes" if k*500>=x else "No")


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const string INF(1,'z'+1);

using PSI = pair<int,string>;

const int MAX_LEN = 500;
PII prv[MAX_LEN][64];
string dp[MAX_LEN][64];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, A, S, GG;
  while(cin>>N>>A>>S>>GG,N){
	int sum = 0;
	vector<vector<PSI>> G(N);
	REP(i,A){
	  int x, y; string s;
	  cin >> x >> y >> s;
	  G[x].EB(y,s);
	  sum += SZ(s);
	}

	REP(i,MAX_LEN) REP(j,64)
	  dp[i][j] = INF, prv[i][j] = MP(-1,-1);
	dp[0][S] = "";
	REP(step,MAX_LEN-1){
	  REP(i,N){
		for(auto& e: G[i]){
		  int nxt_s = step + SZ(e.SS);
		  if(nxt_s < MAX_LEN){
			string s = dp[step][i]+e.SS;
			if(dp[nxt_s][e.FF] > s){
			  dp[nxt_s][e.FF] = s;
			  prv[nxt_s][e.FF] = MP(step,i);
			}
		  }
		}
	  }
	}
	string ans = INF;
	bool ok = true;
	REP(step,MAX_LEN-1){
	  if(ans > dp[step][GG]){
		ok = true;
		PII p(step,GG);
		set<int> memo;
		while(p.SS >= 0){
		  if(memo.count(p.SS)){
			ok = false;
			break;
		  }
		  memo.insert(p.SS);
		  p = prv[p.FF][p.SS];
		}
		ans = dp[step][GG];
	  }
	}
	cout << (ans == INF||!ok?"NO":ans)<<endl;
  }
  return 0;
}

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

int w,h;
bool mp[200][200];
bool used[200][200];
int ans;

int Solve(int x,int y){
  int res=0;
  if(x>w+1 || x<0 || y>h+1 || y<0) return 0;
  if( used[y][x]==1 || mp[y][x]==1 ){ return mp[y][x]; }

  used[y][x]=1;
  res+=Solve(x-1,y)+Solve(x+1,y);
  if(y%2)
    res+=Solve(x,y+1)+Solve(x+1,y+1)+Solve(x,y-1)+Solve(x+1,y-1);
  else res+=Solve(x-1,y+1)+Solve(x,y+1)+Solve(x-1,y-1)+Solve(x,y-1);
  return res;
}


int main(){


  cin >> w >> h;

  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      cin >> mp[i][j];
    }
  }


  cout << Solve(0,0) << endl;

  return 0;
}

Measured memory_bytes: 1560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int N = 1000000;
		boolean[] primes = new boolean[N + 1];
		primes[0] = true;
		primes[1] = true;
		for (int i = 2; i <= Math.sqrt(N); i++) {
			if (!primes[i]) {
				for (int j = i * 2; j <= N; j += i) {
					primes[j] = true;
				}
			}

		}
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int count = 0;
			for (int i = n - 1; i >= n / 2; i -= 2) {
				if (!primes[i] && !primes[n - i]) {
					count++;
				}
			}
			System.out.println(count);
		}

	}
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  for (int i = s.size() - t.size(); ~i; i--) {
    int j = 0;
    for (; j < t.size(); ++j) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        break;
      }
    }
    if (j >= t.size()) {
      for (int j = 0; j < i; ++j) {
        cout << (s[j] == '?' ? 'a' : s[j]);
      }
      for (int j = 0; j < t.size(); ++j) {
        cout << t[j];
      }
      for (int j = i + t.size(); j < s.size(); ++j) {
        cout << (s[j] == '?' ? 'a' : s[j]);
      }
      cout << '\n';
      return 0;
    }
  }
  cout << "UNRESTORABLE\n";
  return 0;
}


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

A = [i for i in map(int, input().split())]
A.sort()
Amax = A[-1]

dp = [1]*(Amax+1)
ans = 0


for i in range(len(A)-1):
    p = A[i]
    if dp[p] == 1:
        for q in range(Amax//p+1):
            dp[p*q] = 0
        if A[i] != A[i+1]:
            ans += 1
if dp[Amax] == 1:
    ans += 1
print(ans)


Measured memory_bytes: 116476
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 100001

#define ll long long 



int main(){
	int a;
	cin>>a;
	cout<<a +a*a +a*a*a<<endl;
	
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int DP[3005][3005];
int DP2[3005][3005];

int main(){
    int N,T;
    cin >> N >> T;
    vector<int> A(N+1), B(N+1);
    rep1(i,N) cin >> A[i] >> B[i];
    
    rep1(i,N) rep(j,3005){
        if(j-A[i]>=0) DP[i][j] = max(DP[i-1][j], DP[i-1][j-A[i]]+B[i]);
        else DP[i][j] = DP[i-1][j];
        
        if(j-A[N-i+1]>=0) DP2[i][j] = max(DP2[i-1][j], DP2[i-1][j-A[N-i+1]]+B[N-i+1]);
        else DP2[i][j] = DP2[i-1][j];
    }

    int ans = 0;
    rep1(i,N){
        int sum = 0;
        rep(j,T) sum = max(sum, DP[i-1][j]+DP2[N-i][T-1-j]);
        ans = max(ans, sum+B[i]);
    }
    
    pr(ans);

}


Measured memory_bytes: 70784
n=int(input())
s=input()

def ZA(n,s):
    Z=[0 for i in range(n)]
    Z[0]=n
    i=1
    j=0
    cand=0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        Z[i]=j
        cand=max(cand,min(Z[i],i))
        if j==0:
            i+=1
            continue
        k=1
        while k<j and k+Z[k]<j:
            Z[i+k]=Z[k]
            cand=max(cand,min(Z[i],i))
            k+=1
        i+=k
        j-=k
    #print(Z)
    return cand


ans=0
for i in range(n):
    ans=max(ans,ZA(n-i,s[i:]))
print(ans)

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


int main(){
int a, b ;
cin >> a>>b;
int ans =20;
rep(i,21){
    if(a*i-i+1>=b){
        ans = min(ans,i);
    }
}
cout << ans << endl;
}  

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

#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long llong;

const int MXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int N = (int)1e3 + 7;

int n, a[MXN];
llong dp[MXN];

int main()
{
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    //dp[i] = MOD;
  }
  dp[1] = 0;
  dp[2] = abs(a[2] - a[1]);
  for(int i = 3; i <= n; i++){
    dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
  }
  /*for(int i = 1; i <= n; i++){
    cout << dp[i] << ' ';
  }*/
  cout << dp[n];
  return 0;
}


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

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

    map<int, bool> s_maps[M];
    for (int i=0; i<M; i++) {
        int k;
        cin >> k;
        map<int, bool> s;
        for (int j=0; j<k; j++) {
            int km;
            cin >> km;
            s[km] = true;
        }
        s_maps[i] = s;
    }

    int p[M];
    for (int i=0; i<M; i++) {
        cin >> p[i];
    }

    int sum = 0;
    for (int bit=0; bit < (1<<N); ++bit) {
        vector<int> checks;
        for (int i=0; i<N; ++i) {
            if (bit & (1 << i)) {
                checks.push_back(i + 1);
            }
        }

        // compare with pi
        int on_bulbs = 0;
        for (int i=0; i<M; ++i) {
            map<int, bool> s_map = s_maps[i];
            int p_i = p[i];

            int on_count = 0;
            for (auto check_ij : checks) {
                auto found_s = s_map.find(check_ij);
                if (found_s != s_map.end()) {
                    on_count++;
                }
            }

            if (on_count % 2 == p_i) {
                on_bulbs++;
            }
        }
        if (on_bulbs == M) {
            sum++;
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 305
#define INF 1000000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m,a[MAXN][MAXN];
int bas[MAXN];
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=m;j>=1;j--)
        {
            if(a[i][j])
            {
                if(!bas[j])
                {
                    bas[j]=i;
                    cnt++;
                    break;
                }
                for(int k=1;k<=m;k++) a[i][k]^=a[bas[j]][k];
            }
        }
    }
    int free=n-cnt,ans=1LL*pow_mod(2,n)%MOD;
    int res=pow_mod(2,free);dec(ans,res);
    ans=1LL*ans*pow_mod(2,m-1)%MOD;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 640
import itertools
n,m=map(int,input().split())
ks=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
sl=list(itertools.product(range(2),repeat=n))
ans=0
for s in sl:
    flg=True
    for i in range(m):
        t=0
        for j in range(ks[i][0]):
            t+=s[ks[i][j+1]-1]
        if t%2!=p[i]:
            flg=False
            break
    if flg:
        ans+=1
print(ans)

Measured memory_bytes: 3188
import sys
M, d = input().split()
if int(d)>=10:
  d10 = int(d[0])
  d1 = int(d[1])
else:
  print(0)
  sys.exit()
M = int(M)
ans = 0
for j in range(2,d10+1):
  for i in range(2,10):
    if 10*j+i>d10*10+d1:
      print(ans)
      sys.exit()
    if M >=j*i:
      ans+=1
print(ans)

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();
		int B = in.nextInt();
		if (B % A == 0) {
			System.out.println(A + B);
		} else {
			System.out.println(B - A);
		}
	}
}


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

const int pos[]={1,0,-1,0};
struct state{
	char x,y,p,mem;
	bool operator==(const state &A)const{
		return A.x==x&&A.y==y&&A.p==p&&A.mem==mem;
	}
};

bool check(state A,const vector<string> &code,int r,int c,vector<state> &visited){
  char op=code[A.y][A.x];
  while(op!='@'){
  	if(find(visited.begin(),visited.end(),A)!=visited.end())return false;
  	visited.push_back(A);
  	op=code[A.y][A.x];
  	//cerr<<(int)A.x<<","<<(int)A.y<<endl;
  	if(op=='>')A.p=0;
  	if(op=='v')A.p=1;
  	if(op=='<')A.p=2;
  	if(op=='^')A.p=3;
  	if(op=='_')A.p=(A.mem)?2:0;
  	if(op=='|')A.p=(A.mem)?3:1;
   	if('0'<=op&&op<='9')A.mem=op-'0';
   	if(op=='+')A.mem=(A.mem+1)%16;
   	if(op=='-')A.mem=(A.mem+15)%16;
   	if(op=='?'){
   		bool f=false;
   		for(int i=0;i<4;++i){
   			state tmp=A;
   			tmp.p=i;
   			tmp.x=(tmp.x+pos[tmp.p]+c)%c;tmp.y=(tmp.y+pos[(tmp.p+3)%4]+r)%r;
   			if(check(tmp,code,r,c,visited))return true;
   		}
   		return false;
   	}
   	
  	A.x=(A.x+pos[A.p]+c)%c;A.y=(A.y+pos[(A.p+3)%4]+r)%r;
  }
  return true;
}

int main(void){
  int r,c;
  cin>>r>>c;
  vector<string> code;
  for(int i=0;i<r;++i){string s;cin>>s;code.push_back(s);}
  state A={0,0,0,0};
  vector<state> visited;
  cout<<(check(A,code,r,c,visited)?"YES":"NO")<<endl;
  return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    string ans = "No";
    for(int i=0; i<=n; i++){
        int an = n-i;
        if(2 * i + 4 * an == k){
            ans = "Yes";
        }
    }
    cout << ans;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	const double PI = acos(-1);
	double a, b, C, rad;
	cin >> a >> b >> C;
	rad = C * PI / 180;
	cout << fixed;
	cout << setprecision(6) << a*b*sin(rad) / 2 << endl << a + b + sqrt(a*a + b*b - 2 * a*b*cos(rad)) << endl << a*b*sin(rad) / a << endl;
	return 0;
}


Measured memory_bytes: 3560
import java.util.*;


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

				if(n==0){
					sc.close();
					break;
				}
				
				int[][] t = new int[n][n+1];
				for (int i=0;i<n;i++){
					for (int j=0;j<=n;j++){
						t[i][j] = sc.nextInt();
					}
				}
				int[] dp = new int[1<<n];
				Arrays.fill(dp,Integer.MAX_VALUE);
				dp[0] = 0;
				
				for (int bit=0;bit<1<<n;bit++){
					for (int i=0;i<n;i++){
						if ((bit & (1<<i)) != 0){
							continue;
						}
						int cost = t[i][0];
						for (int j=0;j<n;j++){
							if ((bit & (1<<j)) == 0){
								continue;
							}
							cost = Math.min(cost, t[i][j+1]);
						}
						int k = bit | (1 << i);
						dp[k] = Math.min(dp[k],dp[bit] + cost);
					}
				}
				System.out.println(dp[(1<<n) - 1]);
			}
			sc.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 35672
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

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

		multiset<int> s;
		while( q-- ) {
			int cmd, x, y;
			cin >> cmd;

			if( cmd == 0 ) {
				cin >> x;
				s.insert( x );
				cout << s.size() << '\n';
			}
			else if( cmd == 1 ) {
				cin >> x;
				cout << s.count( x ) << '\n';
			}
			else if( cmd == 2 ) {
				cin >> x;
				s.erase( x );
			}
			else {
				cin >> x >> y;
				auto a = s.lower_bound( x );
				auto b = s.upper_bound( y );
				while( a != b ) {
					cout << *a << '\n';
					++a;
				}
			}
		}
	}
};

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



Measured memory_bytes: 12412
//close stdin
//https://codeforces.com/problemset?order=BY_RATING_ASC&tags=binary+search%2C1300-
#include <bits/stdc++.h>
using namespace std;
long long  gcd(long long  a, long long b){ 
	if (a == 0) 
		return b;  
	return gcd(b % a, a);  
	} 
long long lcmm(long long a,long long b){
	
return (a*b)/gcd(a, b);
}
	
int mod=998244353;
long long summ(long long x){
	long long ans=0;
	while(x!=0){
		ans+=(x%10);
		x=x/10;
	}
	return ans;
	
}
bool prime[1000003]; 
void SieveOfEratosthenes() 
{ 
	int n=1000002;
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 

} 

int main(){
	//freopen ("t.txt","r",stdin);
	int n,k;
	scanf("%d %d",&n,&k);
	vector<int> arr(n),cost(n,INT_MAX);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	cost[0]=0;

	for(int i=0;i<n;i++){
		for(int j=1;i+j<min(n,k+1+i);j++){
			cost[i+j]=min(cost[i+j],cost[i]+abs(arr[i+j]-arr[i]));
			//cout<<i<<" "<<j<<"\n";
		}
	}
	
	cout<<cost[n-1];
	



return 0;
}


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

using namespace std;

const int MAX_BITS = 63;
int no_of_numbers;
vector <int> no_of_1s(MAX_BITS, 0);

int is_bit_set(long long n, int position)
{
    return ( (n & (1LL << position)) != 0);
}

long long get_mask_with_prefix_till(long long n, int replaced_one)
{
    long long mask = 0;

    for(int bit = MAX_BITS; bit >= 0; bit--)
    {
        if(bit > replaced_one)
        {
            if(is_bit_set(n, bit))
            {
                mask |= (1LL << bit);
            }
        }
        else if(bit == replaced_one)
        {
            continue;
        }
        else
        {
            if(2*no_of_1s[bit] < no_of_numbers)
            {
                mask |= (1LL << bit);
            }
        }
    }

    return mask;
}

long long get_value(vector <long long> &A, long long mask)
{
    long long sum = 0;

    for(int i = 1; i <= no_of_numbers; i++)
        sum += (A[i]^mask);

    return sum;
}

int main()
{
    long long K;
    cin >> no_of_numbers >> K;

    vector <long long> A(no_of_numbers + 1);
    for(int i = 1; i <= no_of_numbers; i++)
        cin >> A[i];

    for(int i = 1; i <= no_of_numbers; i++)
    {
        for(int bit = 0; bit <= MAX_BITS; bit++)
        {
            if(is_bit_set(A[i], bit))
            {
                no_of_1s[bit]++;
            }
        }
    }

    vector <long long> masks;
    masks.push_back(K);
    masks.push_back(0);

    for(int bit = MAX_BITS; bit >= 0; bit--)
    {
        if(is_bit_set(K, bit))
        {
            long long mask = get_mask_with_prefix_till(K, bit);

            masks.push_back(mask);
        }
    }

    long long maximum_value = 0;
    for(int m = 0; m < masks.size(); m++)
    {
        maximum_value = max(maximum_value, get_value(A, masks[m]));
    }

    cout << maximum_value;
    return 0;
}

Measured memory_bytes: 1024
unittest
{
	assert( [ "9 45000" ].parse.expand.solve == "4 0 5" );
	assert( [ "20 196000" ].parse.expand.solve == "-1 -1 -1" );
//	assert( [ "1000 1234000" ].parse.expand.solve == "14 27 959" );		// 解が複数あるのでこれはtrueにならない場合がある
	assert( [ "1000 1234000" ].parse.expand.solve == "26 0 974" );
	assert( [ "2000 20000000" ].parse.expand.solve == "2000 0 0" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ny = input.front.split.to!( long[] );
	return tuple( ny[ 0 ], ny[ 1 ] );
}

auto solve( long n, long y )
{
	for( auto yen10000_n = n; 0 <= yen10000_n; yen10000_n-- )
	{
		auto yen10000_y = yen10000_n * 10000;
		if( y < yen10000_y ) continue;
		
		for( auto yen5000_n = n - yen10000_n; 0 <= yen5000_n; yen5000_n-- )
		{
			auto yen5000_y = yen5000_n * 5000;
			if( y < yen10000_y + yen5000_y ) continue;
			
			auto yen1000_n = n - yen10000_n - yen5000_n;
			auto yen1000_y = yen1000_n * 1000;
			
			if( y == yen10000_y + yen5000_y + yen1000_y )
			{
				return format( "%d %d %d", yen10000_n, yen5000_n, yen1000_n );
			}
		}
	}
	
	return "-1 -1 -1";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int nx=0,ny=0,nt=0;
    int i;
    bool j = 1;
    for(i=0;i<n;i++)
    {
        int t,x,y,de;
        scanf("%d%d%d",&t,&x,&y);
        de = (t-nt)-(abs(x-nx)+abs(y-ny));
        if(j && (de<0 || de%2==1))
            j = 0;
        nx = x;
        ny = y;
        nt = t;
    }
    if(j)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vector<vector<int>>v;
int solve(int i,vector<int>under){
	if(i == n){
		for(int j =0;j<m;j++){
			// cout << under[j] << " " ;
			if(under[j]<k){
				// cout << endl;
				return 1e9;
			}
		}

		// for(int j = 0;j<m;j++){
		// 	cout << under[j]<<" ";
		// }
		// cout << endl;
		return 0;
	}
	int mn = 1e9;
	 mn = min(mn,solve(i+1,under));
	for(int j =1;j<=m;j++){
		under[j-1]+=v[i][j];
	
	}
	mn = min(solve(i+1,under)+v[i][0],mn);
	// cout << mn<<endl;
	return mn;
}
int main(){

	cin >> n >> m >> k;
	vector<int>tmp(m+10,0);
	v.resize(n+10,tmp);
	for(int i  =0;i<n;i++){
		for(int j=0;j<=m;j++){
			cin >> x;
			v[i][j]=(x);
		}
	}
	vector<int>arr;
	arr.resize(m+10,0);
	int x =solve(0,arr);
	if(x==1e9){
		cout << -1;
	}else{
		cout << x;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<ll> A(N);
    rep(i, N) cin >> A[i];

    vec<vec<ll>> dp(N + 2, vec<ll>(2, -1));
    dp[0][0] = 1000;    // 日数、枚数、金額

    ll amari = 0;
    rep(i, N) rep(j, 3) {
        ll price = A[i];
        dp[i+1][0] = max(dp[i][0],dp[i][1]*price + amari);

        if(dp[i][0]/price > dp[i][1]){
            dp[i+1][1] = dp[i][0]/price;
            amari =  dp[i][0]%price;
        } else if(dp[i][0]/price < dp[i][1]){
            dp[i+1][1] = dp[i][1];
        } else {
            dp[i+1][1] = dp[i][1];
            amari = max(amari,dp[i][0]%price);
        }
        
    }

    cout << dp[N][0] << endl;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    char b;
    scanf("%c", &b);
    if (b == 'A')
        printf("T\n");
    else if (b == 'C')
        printf("G\n");
    else if (b == 'T')
        printf("A\n");
    else
        printf("C\n");
    return 0;
}

Measured memory_bytes: 128
#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;
using ll = long long;

const ll mod = 1000000007;

ll powmod(ll x, ll y) {
    ll res = 1;
    for (ll i = 0; i < y; i++) {
        res = res * x % mod;
    }
    return res;
}

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

    ll ans = powmod(10, N) - powmod(9, N) - powmod(9, N) + powmod(8, N);
    ans %= mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll all = a + b + c;
  if(max({a,b,c}) == all - max({a,b,c}))cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main(){
    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s (D, vector<int>(26));
    vector<int> t(D);
    vector<int> last(26);

    REP(i, 26){
        cin >> c[i];
    }
    REP(i, D){
        REP(j, 26){
            cin >> s[i][j];
        }
    }
    REP(i, D){
        cin >> t[i];
    }

    ll st = 0, los = 0;
    REP(i, D){
        st += s[i][t[i]-1];
        last[t[i]-1] = i+1;
        //cout << st << endl;   //満足度の低下を考えない場合
        REP(j, 26){
            los += c[j]*(i+1 - last[j]);
        }
        //cout << st << endl;
        cout << st - los << endl;
    }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int a, b;
	cin >> a >> b;
	if (a < 6)
		cout << 0 << endl;
	else if(a > 12)
		cout << b << endl;
	else
		cout << b / 2 << endl;
}

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

	solve();
}

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


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = ReadIntArray();
            int N = nk[0], K = nk[1];
            Out(N - K + 1);
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

    class PriorityQueue<T>
    {
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200000 + 5;
const double PI = acos(-1);
#define ll long long

class TaskC {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		ll pos, steps, jump;
		cin >> pos >> steps >> jump;
		
		ll ans = (ll)1e18;
		if(pos <= 0) {
			// pos + k*jump <= 0
			ll k = -pos/jump;
			if(k > steps) {
				cout << abs(pos + steps*jump) << endl;
				return;
			}
			steps -= k;
			if(steps % 2 == 0) {
				cout << abs(pos + k*jump) << endl;
			} else {
				ll op2 = abs(pos + (k+1)*jump);
				cout << op2 << endl;	
			}
		} else {
			// pos - k*jump >= 0
			// pos / jump >= k , k <= pos/jump
			ll k = pos / jump;
			if(k > steps) {
				cout << abs(pos - steps*jump) << endl;
				return;
			}
			steps -= k;
			if(steps % 2 == 0) {
				cout << abs(pos - k*jump) << endl;
			} else {
				ll op1 = abs(pos - (k-1)*jump);
				ll op2 = abs(pos - (k+1)*jump);
				cout << min(op1, op2) << endl;
			}
		}
	}
	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3612