akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#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>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する
#define MOD 1000000007

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), dx;
    vector<ll> y(m), dy;
    rep(i, 0, n) {
        cin >> x[i];
    }
    rep(i, 0, m) {
        cin >> y[i];
    }
    rep(i, 0, n - 1) {
        dx.push_back(x[i + 1] - x[i]);
    }
    rep(i, 0, m - 1) {
//        cin >> y[i];
        dy.push_back(y[i + 1] - y[i]);
    }

    ll sum_x = 0LL;
    rep(i, 0, n - 1) {
        int a1 = i + 1;
        int b1 = dx.size() - i;
//        sum_x = (dx[i] * (i + 1) * (n - 1 - i) + sum_x) % MOD;
        sum_x = ((dx[i] * (i + 1) % MOD) * (n - 1 - i) + sum_x) % MOD;
    }
    ll ans = 0LL;
    rep(i, 0, m - 1) {
//        sum_x = (x[i] * (i + 1) * (n - i) + sum_x) % MOD;
        int a1 = i + 1;
        int b1 = n - i - 1;
        ans = (ans + ((sum_x * dy[i] % MOD) * (i + 1) % MOD) * (m - 1 - i)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<string> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	int count = 0;
	int twin = 0;
	int begin = 0;
	int end = 0;
	for (int i = 0; i < N; i++) {
		if(vec.at(i).at(0) == 'B' && vec.at(i).at(vec.at(i).size() - 1) == 'A'){
			twin++;
		}
		if (vec.at(i).at(0) == 'B' && vec.at(i).at(vec.at(i).size() - 1) != 'A') {
			begin++;
		}
		if (vec.at(i).at(0) != 'B' && vec.at(i).at(vec.at(i).size() - 1) == 'A') {
			end++;
		}
		for (int k = 0; k < vec.at(i).size() - 1; k++) {
			if (vec.at(i).at(k) == 'A' && vec.at(i).at(k + 1) == 'B') {
				count++;
			}
		}
	}
	if (twin != 0) {
		count += twin - 1;
		if (begin != 0) {
			count++;
		}
		if (end != 0) {
			count++;
		}
		if (begin != 0 && end != 0) {
			count += min(begin, end) - 1;
		}
	}
	else {
	     count += min(begin, end);
	}
	cout << count << endl;
} 

Measured memory_bytes: 768
import java.io.*;

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder(br.readLine());
		int q = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < q; i++){
			String[] s = br.readLine().split(" ");
			
			if(s[0].equals("replace")){
				sb.replace(Integer.parseInt(s[1]), Integer.parseInt(s[2]) + 1, s[3]);
			}
			else if(s[0].equals("reverse")){
				StringBuilder re = new StringBuilder(sb.substring(Integer.parseInt(s[1]), Integer.parseInt(s[2]) + 1));
				String reverse = new String(re.reverse());
				sb.replace(Integer.parseInt(s[1]), Integer.parseInt(s[2]) + 1, reverse);
			}
			else if(s[0].equals("print")){
				String print = sb.substring(Integer.parseInt(s[1]), Integer.parseInt(s[2]) + 1);
				System.out.println(print);
			}
		}
	}
}

Measured memory_bytes: 24884
#include <iostream>                                                                
using namespace std;                                                               
                                                                                   
int main(void) {                                                                   
  int n;                                                                           
  cin >> n;                                                                        
  for (int i=1; i<=n; i++) {                                                       
    if (i%3==0) {                                                                  
      cout << " " << i << flush;                                                   
      continue;                                                                    
    }                                                                              
      int x = i;                                                                   
      while (x!=0) {                                                               
        if (x%10==3) {                                                             
          cout << " " << i << flush;                                               
          break;                                                                   
        }                                                                          
        x /= 10;                                                                   
      }                                                                            
    }                                                                              
  cout << endl;                                                                    
  return 0;                                                                        
}                                                                                  
                                       

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define N 200100
using namespace std;
long long n;
static long long a,b;
bool ok(long long x)
{
	long long s=x/2;
	for(long long i=s-1000ll;i<=s+1000ll;i++)
		if(i>0&&i<=x)
		{
			if((i>=a?i+1:i)*((x-i+1)>=b?x-i+2:x-i+1)>=a*b)return false;
		}
	return true;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		long long l=0,r=2000000000ll;
		while(l<r)
		{
			long long Mid=(l+r+1)>>1;
			if(ok(Mid))l=Mid;
			else r=Mid-1;
		}
		cout<<l<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define int long long
#define pb push_back

using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
        while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
   return f * x ;
}

int n , m , ans , now ;

signed main (int argc , char * argv[] ) {
    n = rint () ; m = rint () ; now = 1 ;
    if ( m == 1 ) { puts ("0") ; return 0 ; }
    while ( true ) {
        -- now ; now += n ; ++ ans ;
        if ( now >= m ) break ;
    }
    printf ("%lld\n" , ans ) ;
    return 0 ;
}

Measured memory_bytes: 256
N,M= map(int, input().split())
A=[list(map(int, input().split())) for _ in range(N)]
A.sort()
a=0
b=0
for i in range(N):
  if a+A[i][1]<M:
    b+=A[i][0]*A[i][1]
    a+=A[i][1]
    continue
  else:
    b+=A[i][0]*(M-a)
    break
print(b)

Measured memory_bytes: 27760
use std::io;
     
    fn next_vec() -> Vec<i64> {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().map(|n| n.parse().unwrap()).collect()
    }
     
    fn main() {
        let mut v = next_vec();
        let a = v[0];
        let b = v[1];
        let c = v[2];
     
        if v.iter().fold(1, |sum, &x| sum * x) % 2 == 1 {
            v.sort();
            println!("{}", v[1] * v[0]);
        } else {
            println!("0");
        };
  }

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r,d,c=0,f=0;
    cin>>n;
    r=n%100;
    d=n/100;
    if(r>=1 && r<=12 )
    {
        c++;
    }
    if(d>=1 && d<=12 )
    {
        f++;
    }

    if( c>0 && f>0)
    {

        cout<<"AMBIGUOUS"<<endl;

    }
    else if( c>0)
    {
        cout<<"YYMM"<<endl;
    }

    else if( f>0)
    {
        cout<<"MMYY"<<endl;
    }

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

    return 0;

}


Measured memory_bytes: 3616
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
dx=[0,0,1,-1,1,1,-1,-1]
dy=[1,-1,0,0,-1,1,-1,1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x and x<h and 0<=y and y<w and s[x][y]=="#":
                    cnt+=1
                s[i][j]=cnt
for i in range(h):
    print(*s[i],sep="")


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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;
  int d[m]; rep(i, m) cin >> d[i];
  int a[m-1];

  sort(d, d+m);
  int x; x = d[0];
  rep(i, m-1) {
    int y; y = d[i+1];
    a[i] = abs(x-y);
    x = y;
  }
  sort(a, a+m-1);
  
  int ans = 0;
  if(m <= n) {
    cout << 0; return 0;
  }
  int asize = sizeof(a)/sizeof(a[0]);
  int range = asize-n+1;
  rep(i, range) {
    ans += a[i];
  }
  cout << ans;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) cout<<"Yes" ;
	else if(s[0]==s[2]&&s[1]==s[3]&&s[1]!=s[0]) cout<<"Yes" ;	
	else if(s[0]==s[3]&&s[1]==s[2]&&s[1]!=s[0]) cout<<"Yes" ;	
	else cout <<"No";		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
    using namespace std;
    using namespace __gnu_pbds;
    typedef long long ll; 
    #define int long long
    typedef unsigned long long lu;
    typedef vector<ll> v;
    typedef vector<vector<ll> > vv;
    typedef vector<string>  vs;
    typedef vector<pair<ll,ll>> vpr;
    typedef long double ld;
    #define f(i,n) for(ll i = 0; i < n; i++)
    #define ff(i,n) for(ll i=1;i<=n;i++)
    #define pb push_back
    #define mp make_pair
    #define endl "\n"
    #define fi first
    #define se second
    #define all(x) x.begin(),x.end()
    #define rall(x) x.rbegin(),x.rend()
    #define amax(x,y) if(y>x) x=y;
    #define amin(x,y) if(y<x)x=y;
    #define bg(x) x.begin()
    #define sz(x) (ll)x.size()
    #define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
    #define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
    #define mxt(a) *(max_element(a.begin(),a.end()))
    #define mnt(a) *(min_element(a.begin(),a.end())
    #define tc ll t;cin>>t;while(t--)
    typedef pair<ll,ll> pi;
    #define yes cout<<"Yes\n";
    #define no cout<<"No\n";
    #define yesno(f) if(f) yes else no
    const v dx = {1, -1, 0, 0};
    const v dy = {0, 0, 1, -1};
    const ll mod=1e9+7;
    const ld PI = 2 * acos(0.0);
    ll m(ll a){ return (a+mod)%mod;}
    ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
    ll power(ll a,ll b,ll m)
    {
        if(b==0)
            return 1;
        ll d=power(a,b/2,m);
        d=(d*d)%m;
        if(b&1)
            d=(d*a)%m;
        return d;
    }
    // set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
    // set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
    /*string operations :
    str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
    str.substr (x) : returns a substring str[x],... end of string
    str.find(qtr) : returns the first occurenece of qtr in str */
    int solve(){}
    int32_t main()
    {
        int x;cin>>x;
        cout<<(x/500)*1000+((x%500)/5)*5<<endl;
        return 0;
    }

Measured memory_bytes: 256
main_num = raw_input()
num_list = map(int, raw_input().split())

fake_counter = 0
counter = 0

while True:
  if num_list[counter] != counter + 1:
    fake_counter += 1
  counter += 1
  if counter >= int(main_num):
    break

if fake_counter > 2:
  print "NO"
else:
  print "YES"

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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    rep(i,n)a[i]--;
    int b[n];
    b[0]=1;
    int old = 0;
    int cnt = 0;
    rep(i,n){
        b[old]=0;
        b[a[old]]=1;
        old = a[old];
        cnt++;
        if(old == 1){
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
	string s, t = "JOI";
	cin >> s;
	s += 'X';
	int ans = 0, f = -1, now = 0, pre = 0;
	rep(i, 0, s.size()) {
		if (s[i] == t[f]) {
			now++;
		}
		else if (f == 0 && s[i] == t[1]) {
			pre = now;
			now = 1;
			f = 1;
		}
		else if (f == 1 && s[i] == t[2]) {
			if (pre < now) {
				f = -1;
			}
			else {
				f++;
				pre = now;
				now = 1;
			}
		}
		else if (f == 2 && s[i] != t[2]) {
			if (pre <= now) ans = max(ans, pre);
			f = -1;
		}
		else {
			f = -1;
		}
		if (f == -1 && s[i] == 'J') {
			f = 0;
			now = 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2056
a1=[int(i) for i in input().split()]
a2=[int(i) for i in input().split()]
a3=[int(i) for i in input().split()]
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        if a1[j]==b: a1[j]=-1
        if a2[j]==b: a2[j]=-1
        if a3[j]==b: a3[j]=-1
if a1[0]+a2[0]+a3[0]==-3 or a1[1]+a2[1]+a3[1]==-3 or a1[2]+a2[2]+a3[2]==-3:
    print("Yes")
    exit()
print("Yes" if sum(a1)==-3 or sum(a2)==-3 or sum(a3)==-3 or a1[0]+a2[1]+a3[2]==-3 or a1[2]+a2[1]+a3[0]==-3 else "No" )


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              (2*acos(0.0))



int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,m;
        cin>>n>>m;
        priority_queue<ll> a;
        loop(i,0,n-1)
        {
            ll x;
            cin>>x;
            a.push(x);
        }
        loop(i,0,m-1)
        {
            ll x=a.top();
            a.pop();
            a.push(x/2);
        }
        ll ans=0;
        loop(i,0,n-1)
        {
            ans+=a.top();
            a.pop();
        }
        cout<<ans;


    }
    return 0;
}


Measured memory_bytes: 4264
import sys
sys.setrecursionlimit(10 ** 9)

def search_island(h, w, max_h, max_w):
    for i in range(8):
        next_h = h + [1, 1, 0, -1, -1, -1, 0, 1][i]
        next_w = w + [0, 1, 1, 1, 0, -1, -1, -1][i]
        if not 0 <= next_h < max_h or not 0 <= next_w < max_w:
            continue
        elif step[next_h][next_w] or not field[next_h][next_w]:
            continue
        step[next_h][next_w] = True
        search_island(next_h, next_w, max_h, max_w)

while True:
    max_w, max_h = map(int, input().split())
    if max_w == max_h == 0:
        break
    field = [[int(i) for i in input().split()] for _ in range(max_h)]
    step = [[False for _ in range(max_w)] for _ in range(max_h)]
    island = 0
    for i in range(max_h):
        for j in range(max_w):
            if step[i][j] or not field[i][j]:
                continue
            search_island(i, j, max_h, max_w)
            island += 1
    print(island)


Measured memory_bytes: 7888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int X = Integer.parseInt(scanner.next());

        scanner.close();

        if (X >= 1200) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }
}


Measured memory_bytes: 25300
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	string s,t;
	cin>>s>>t;
	int cnt=0;
	for(int i=0;i<3;i++)if(s[i]==t[i])cnt++;
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
#include <tuple>

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (ll (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (ll (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (ll (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (ll (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'

#define test if(1)if(0)cerr
using namespace std;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;

const int maxn = 1e5+1;
ll cnt[maxn];
ll a, b, k, n;

int main()
{
    cin >> n >> k;
    rep(i, n)
    {
        cin >> a >> b;
        cnt[a] += b;
    }
    ll cur = 0;
    for (int i = 1; i < maxn; ++i)
    {
        cur += cnt[i];
        if (cur >= k)
        {
            cout << i << newline;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	final int n = stdin.nextInt();
	final int size = 2 * n;
	final int[] cards = new int[ size + 1 ];
	final int[] cardsTo = new int[ size + 1 ];
	for ( int i = 1; i <= size; i++ ) {
	    cards[ i ] = i;
	}
	final int m = stdin.nextInt();

	for ( int t = 0; t < m; t++ ) {
	    final int k = stdin.nextInt();
	    if ( k == 0 ) {
		for ( int i = 1; i <= n; i++ ) {
		    cardsTo[ 2 * i - 1 ] = cards[ i ];
		    cardsTo[ 2 * i ] = cards[ i + n ];
		}
	    } else {
		for ( int i = 1; i <= k; i++ ) {
		    cardsTo[ size - k + i ] = cards[ i ];
		}
		for ( int i = k + 1; i <= size; i++ ) {
		    cardsTo[ i - k ] = cards[ i ];
		}
	    }
	    System.arraycopy( cardsTo, 1, cards, 1, size );
	}
	for ( int i = 1; i <= size; i++ ) {
	    System.out.println( cards[ i ] );
	}
    }    
}

Measured memory_bytes: 20452
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {

	int N;
	int box;
	vector<int> a;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> box;
		a.push_back(box);
	}

	sort(a.begin(), a.end());
	
	int A = 0, B = 0;

	for (int j = N-1; j >=0; j=j-2) {
		A += a[j];
		a.pop_back();

		if (a.begin()==a.end())
			break;

		B += a[j - 1];
		a.pop_back();

		if (a.begin()==a.end())
			break;
	}

	cout << A - B << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
string s;
  cin>>s;
if(s=="SSS")cout<<0;
  else if(s=="SSR") cout<<1;
  else if(s=="SRR") cout<<2;
  else if(s=="SRS") cout<<1;
  else if(s=="RSS") cout<<1;
  else if(s=="RSR") cout<<1;
  else if(s=="RRR") cout<<3;
  else if(s=="RRS") cout<<2;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

  int n1=n+1;
  vector<int> v(n1),w(n1);
  rep_range(i,1,n1){
    cin>>v[i]>>w[i];
  }

  int memd=11;
  // 深さmemdまでは事前に全探索して保持
  // 深さmemdからはその場で全探索

  int maxw=1e5+1;
  vector<vector<int>> dp((1<<memd)+1,vector<int>(maxw));
  dp[0]=vector<int>(maxw,0);
  rep_range(i,1,(1<<memd)+1){
    if(i>=n1) break;
    rep(wn,maxw){
      dp[i][wn]=dp[i/2][wn];
      if(wn-w[i]>=0) chmax(dp[i][wn], dp[i/2][wn-w[i]]+v[i]);
    }
  }

  int q;
  cin>>q;
  rep(t,q){
    int i,l;
    cin>>i>>l;

    int s=0;
    vector<int> vo,wo;
    while(i>(1<<memd)){
      vo.push_back(v[i]);
      wo.push_back(w[i]);
      s++;
      i/=2;
    }

    int ans=0;
    rep(k,1<<s){
      int wn=0,vn=0;
      rep(b,s) if(k&(1<<b)){
        vn+=vo[b];
        wn+=wo[b];
      }
      if(wn>l) continue;
      vn+=dp[i][l-wn];
      chmax(ans,vn);
    }

    cout<<ans<<endl;
  }

}

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


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

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

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int n, q;
  cin >> n >> q;
  vector< vector<int> > a(n);

  rep(i,q) {
    int command;
    cin >> command;
    if (command == 0) {
      int t, x; cin >> t >> x;
      a[t].push_back(x);
    } else if (command == 1) {
      int t; cin >> t;
      rep(i,a[t].size()) {
        if (i) cout << " ";
        cout << a[t][i];
      }
      cout << endl;
    } else {
      int t; cin >> t;
      a[t].clear();
    }
  }

  return 0;
}



Measured memory_bytes: 5776
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, a[300009], cnt[100];

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

void fun(long long cur)
{
	long long tmp = 1, pos = 0;
	while (tmp <= cur) {
		if (tmp & cur) {
			cnt[pos]++;
		}
		tmp = tmp << 1;
		pos++;
	}
}

long long gun(int x)
{
	long long ret;
	ret = cnt[x] * 1LL * (n - cnt[x]);
	ret %= MOD;
	long long tmp = 1LL << x;
	tmp %= MOD;
	ret = ret * tmp;
	ret %= MOD;
	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		fun(a[i]);
	}
	long long ans = 0;
	for (int i = 0; i <= 61; i++) {
		ans += gun(i);
		ans %= MOD;
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 2560
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
mod = 10**9+7
n = I()
if n == 1:
  print(0)
else:
  ##（すべての順列）-（0をつかってないもの）-（9をつかってないもの）+（0も9もつかってないもの）
  print((10**n-2*9**n+8**n)%mod)

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

ll N,M;

int main(){
    cin >> N >> M;
    if(N>=13) cout << M << endl;
    else if(N>=6 && N<=12) cout << M/2 << endl;
    else cout << 0 << endl;
    return 0;
}

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


int main()
{
	int *S, n;
	int *T, q;
	int count;
	int i, j;


	scanf("%d", &n);
	S = (int *)malloc(sizeof(int) * n);
	for(i = 0; i < n; i++)
		scanf("%d", &S[i]);

	scanf("%d", &q);
	T = (int *)malloc(sizeof(int) * q);
	for(i = 0; i < q; i++)
		scanf("%d", &T[i]);


	count = 0;
	for(i = 0; i < q; i++){
		for(j = 0; j < n; j++){
			if(T[i] == S[j]){
				count++;
				break;
			}
		}
	}


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

	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> s(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		sum += s[i];
	}

	if (sum % 10) {
		cout << sum << "\n";
	} else {
		sort(s.begin(), s.end());
		for (int i = 0; i < n; ++i) {
			sum -= s[i];
			if (sum % 10) {
				cout << sum << "\n";
				return 0;
			}

			sum += s[i];
		}

		cout << "0\n";
	}	

	return 0;

}

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

signed main()
{
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int cnt=0;
	while(n!=0){
		cnt++;
		n/=k;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static int gcd(int a ,int b){return b>0? gcd(b,a%b):a;}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();
    int count = 0;
    int max_gcd = gcd(a,b);
    int ans=0;

    for(int i= max_gcd; i>0; i--){
      if(a%i==0 && b%i==0){
        count += 1;
      }
      if(count == k){
        ans = i;
        break;
      }
    }
    System.out.println(ans);

  }
}

Measured memory_bytes: 22996
#include<iostream>
#include<queue>
#include<functional>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>Q;
vector<pair<ll, ll>>X[1 << 18]; ll N, M, P1, P2, V, W, A, B, K[1 << 18], dist[1 << 18], J[1 << 18];
void dijkstra() {
	while (!Q.empty()) {
		ll G1 = Q.top().first, G2 = Q.top().second; Q.pop();
		for (int i = 0; i < X[G2].size(); i++) {
			if (dist[X[G2][i].first] > dist[G2] + X[G2][i].second) {
				dist[X[G2][i].first] = dist[G2] + X[G2][i].second;
				Q.push(make_pair(dist[X[G2][i].first], X[G2][i].first));
			}
		}
	}
}
int main() {
	cin >> N >> M >> V >> W >> P1 >> P2; fill(dist, dist + (1 << 18), 1LL << 62);
	for (int i = 0; i < V; i++) { cin >> A; Q.push(make_pair(0, A)); dist[A] = 0; J[A] = 1; }
	for (int i = 0; i < M; i++) { cin >> A >> B; X[A].push_back(make_pair(B, 1)); X[B].push_back(make_pair(A, 1)); }
	dijkstra();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < X[i].size(); j++) {
			if (X[i][j].first == 1 || X[i][j].first == N)X[i][j].second = 0;
			else if (J[X[i][j].first] == 1)X[i][j].second = 1LL << 61;
			else if (dist[X[i][j].first] <= W)X[i][j].second = P2;
			else { X[i][j].second = P1; }
		}
	}
	fill(dist, dist + (1 << 18), 1LL << 62); dist[1] = 0; Q.push(make_pair(0, 1)); dijkstra();
	cout << dist[N] << endl;
	return 0;
}

Measured memory_bytes: 22884
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int a,b,k;
  cin >> a >> b >>k;
  
  if(b-a<(2*k)){
  	for(int i=a; i<=b; i++) cout << i << endl;
  }
	else{
    	for(int i=a; i<(a+k); i++) cout << i << endl;
      for(int i=b-k+1; i<=b; i++) cout << i << endl;
    }
  
 
}

Measured memory_bytes: 256
h,w = map(int, raw_input().split())
c = [ raw_input() for i in range(h) ]
ans = True
for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            ans = False
            if (i > 0) and (c[i-1][j] == '#'):
                ans = True
            if (j > 0) and (c[i][j-1] == '#'):
                ans = True
            if (i < h-1) and (c[i+1][j] == '#'):
                ans = True
            if (j < w-1) and (c[i][j+1] == '#'):
                ans = True
        if not(ans):
            break
    if not(ans):
        break
if ans:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
const int ms = 58;
int s[ms][2], c[ms][2];


int main(){
	int maxi = 0;
	int n,m;
	cin >> n >> m;
	for(int i = 0;i<n;i++) cin >> s[i][0] >> s[i][1];
	for(int i = 0;i<m;i++) cin >> c[i][0] >> c[i][1];
	
	for(int i = 0;i<n;i++){
		maxi = 0x3f3f3f3f;
		int id=0;
		for(int j =0 ;j<m;j++){
			int val = abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1]);
			if(val <maxi){
				maxi = val;
				id = j+1;
			}
		}
	cout<<id<<endl;
	
	}
	

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin



############################################

import numpy as np
# read data for n sequences.
a = int(stdin.readline().split()[0])
n = []
for i in range(a):
    write = stdin.readline().split()
    n.append([write[0],-int(write[1]),i])
#    b = str(n[0])
#    c = int(n[1])
#word = str(stdin.readline().split()[0])

n2 = sorted(n, key=lambda x:(x[0], x[1]))


for el in n2:
    print(el[2]+1)

Measured memory_bytes: 21268
import Control.Monad
import Control.Applicative
import Data.List

solve :: [String] -> [String]
solve [] = []
solve (ini:m:ls) =
    let (ns, ns') = splitAt (read m) ls in
    (foldl' shuffle ini $ map read ns) : solve ns'
    where
    shuffle :: String -> Int -> String
    shuffle s n =
        let (a,b) = splitAt n s in
        b ++ a

main =
    mapM_ putStrLn =<< solve . takeWhile (/= "-") . lines <$> getContents

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N)
  {
    int X;
    cin >> X;
    P[X - 1] = i;
  }
  int ans = 0;
  int count = 1;
  rep(i, N - 1)
  {
    if (P[i] < P[i + 1])
      count++;
    else
    {
      ans = max(ans, count);
      count = 1;
    }
  }
  ans = max(ans, count);
  cout << N - ans << endl;
  return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <fstream>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)

using namespace std;

const int MAXS = 10000;
vector<int> ve;
bool f[2][2 * MAXS + 1];
string s;

bool is_possible(const vector<int> &ve, int type, int S) {
  if (S + MAXS < 0 || S + MAXS > 2 * MAXS) return false;

  memset(f, false, sizeof(f));
  int t = 0, oldt;
  f[t][MAXS] = true;

  for (size_t i = 0; i < ve.size(); i++) {
    if (i % 2 == type) {
      oldt = t;
      t ^= 1;
      memset(f[t], false, sizeof(f[t]));
      for (int s = 0; s < 2 * MAXS; s++) {
        if (! f[oldt][s]) continue;
        f[t][s + ve[i]] = f[t][s - ve[i]] = true;
      }
    }
  }
  return f[t][S + MAXS];
}

int main() {
  int ex, ey;
  ios::sync_with_stdio(false);
  while (cin >> s) {
    cin >> ex >> ey;
    ve.clear();
    for (auto c: s) {
      if (c == 'F') {
        if (ve.empty()) ex--;
         else ve[ve.size() - 1] ++;
      } else if (c == 'T') {
        ve.push_back(0);
      }
    }

    if (is_possible(ve, 1, ex) && is_possible(ve, 0, ey)) {
      cout << "Yes" << endl;
    } else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <boost/math/common_factor.hpp>
#include <boost/bind.hpp>
using namespace std;
using namespace boost;

int main(){
  int a, b;

  while(cin >> a >> b){
    
    cout<<boost::math::gcd(a, b)<< ' ';
    cout<<boost::math::lcm(a, b)<<std::endl;
    
  }
  return 0;
}

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

int main()
{
	int inning ;
	int point = 0 , out = 0 , runner = 0 ;
	char get[10] ;

	cin >> inning ;

	int i = 0 ;
	while( i < inning )
	{
		cin >> get ;
		if( strcmp(get,"HIT") == 0 )
		{
			runner ++ ;
			if( runner == 4 )
			{
				point ++ ;
				runner = 3 ;
			}
		}
		else if( strcmp(get,"HOMERUN") == 0 )
		{
			point += (runner+1) ;
			runner = 0 ;
		}
		else if( strcmp(get,"OUT") == 0 )
		{
			out ++ ;

			if( out == 3 )
			{
				cout << point << endl ;
				i ++ ;
				point = 0 ;
				out = 0 ;
				runner = 0 ;
			}
		}
	}
	return 0 ;
}

Measured memory_bytes: 1164
// AOJ 2508
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<cctype>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int n;
int k[100];
std::string s;

char step( int i )
{
	bool fl = isupper(s[i]);
	int t = s[i]-(fl?'A':'a')-k[i%n];

	while( t < 0 )
		t += 26, fl ^= true;

	return t+(fl?'A':'a');
}

int main()
{
	while( std::cin >> n, n )
	{
		rep( i, n )
			std::cin >> k[i];
		std::cin >> s;

		rep( i, s.size() )
			std::cout << step(i);

		std::cout << std::endl;
	}

	return 0;
}

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

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

fn prime_factorize(mut p: u64) -> Vec<(u64, u64)> {
    let mut res: Vec<(u64, u64)> = Vec::new();
    let mut a = 2;
    while a * a <= p {
        if p % a != 0 {
            a += 1;
            continue;
        }
        let mut ex = 0;
        while p % a == 0 {
            ex += 1;
            p /= a;
        }
        res.push((a, ex));
        a += 1;
    }

    if p != 1 {
        res.push((p, 1));
    }
    res
}

fn main() {
    let n: u64 = read();
    let p: u64 = read();

    //整数pを素数指数表現のデータにする
    let p_f = prime_factorize(p);
    let mut factor: Vec<(u64, u64)> = Vec::new();

    for i in 0..p_f.len() {
        if p_f[i].1 >= n {
            factor.push(p_f[i]);
        }
    }

    let mut ans = 1;
    for i in 0..factor.len() {
        ans *= factor[i].0.pow((factor[i].1 / n) as u32);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N, M; cin >> N >> M;
  vector<int> b(M, 0);
  for (int i = 0; i < N; ++i) {
    int K; cin >> K;
    for (int j = 0; j < K; ++j) {
      int A; cin >> A; --A;
      b[A]++;
    }
  }

  int cnt = 0;
  for (int i = 0; i < M; ++i) {
    if (b[i] == N) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int N; cin >> N;
  map<char, ui> res{};
  for (int i = 0; i < N; ++i) {
    char c; cin >> c;
    ++res[c];
  }
  auto ans = res.size() > 3;
  cout << (ans ? "Four" : "Three") << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <climits>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int a[] =   {4,1,4,1,2,1,2,1};
	int dic[] = {7,2,6,0,4,1,5,3};
	int b[8] = {};
	while(cin >> b[0]) {
		rep2(i,1,8) cin >> b[i];
		int cnt[8] = {};
		int min = INT_MAX;
		rep(i,8) {
			int ret = 0;
			rep(j,8) {
				if(a[(i+j)%8] < b[j]) ret += b[j] - a[(i+j)%8];
			}
			cnt[i] = ret;
			if(ret < min) min = ret;
		}
		int ans = -1;
		rep(i,8) {
			if(min == cnt[i]) {
				if(ans == -1) ans = i;
				else {
					if(dic[ans] > dic[i]) ans = i;
				}
			}
		}
		cout << a[ans];
		rep2(i,1,8) {
			cout << " " << a[(ans+i)%8];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e6+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


ll expo( ll base, ll exp, ll m = MOD )
{
    ll res = 1;
    while( exp > 0 )
    {
        if( exp&1 )
        {
            res *= base;
            res = mod(res,m);
        }
        base *= base;
        base = mod(base,m);
        exp /= 2;
    }
    res = mod(res,m);
    return res;
}

ll modinv( ll n, ll m = MOD )
{
    return expo(n,m-2,m);
}

ll fact[MAXN], invfact[MAXN];
ll choose( ll n, ll k )
{
    if( k >= 0 && k <= n )
    {
        ll ans = fact[n];
        ans = mod( ans * invfact[n-k] );
        ans = mod( ans * invfact[k] );
        return ans;
    }
    return 0;
}


int main() 
{
    fastio();

    fact[0] = invfact[0] = 1;
    for(int i=1;i<MAXN;i++)
    {
        fact[i] = mod(fact[i-1]*i);
        invfact[i] = modinv(fact[i]);
    }

    ll x,y;
    cin>>x>>y;

    ll ans = 0;
    for(int twox=0; 2*twox <= x; twox++ )
    {
        ll remx = x - 2*twox;
        ll dy = twox + 2*remx;
        if( dy == y )
        {
            ans = mod( ans + choose(twox+remx,twox) );
        }
    }
    cout<<ans,nl;
    return 0;
}

Measured memory_bytes: 15872
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl

const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;






int main(){
    fastio();
    
    
        
        //write code here
        ll x,k,d;
        cin>>x>>k>>d;
        x=abs(x); k=abs(k); d=abs(d);
        ll val=x/d;
        x-=(min(val,k)*d);
        if((k-min(val,k))%2==0){
            cout<<x<<endl;
        }else{
            cout<<d-x<<endl;
        }

        
    
    return 0;
}

 

Measured memory_bytes: 3196
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    in_arr(int, a, n);
    in_arr(int, b, n);
    in_arr(int, c, n - 1);
    int previ = -2;
    int ans = 0;
    repi(i, a) {
        int j = *i - 1;
        ans += b[j];
        if(previ + 1 == j) {
            ans += c[j - 1];
        }
        previ = j;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    int KA = A/K, KB = B/K;
    string ans = "OK";
    if (B<K) {
        ans = "NG";
    }
    else if (B-A<K and A>K*KA and B<K*(KA+1)) {
        ans = "NG";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584